hodmin 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hodmin/hodmin_tools.rb +44 -14
- data/lib/hodmin/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 633ba0e1284ac259815ac6780c0fe8e903f01abe
|
4
|
+
data.tar.gz: 72d81747ae99df84f8beb6b2d2299b9e547e6eee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c7a4b16c02349d8c2b8cee0f5298aca28aed5bf034aa674d89f788bfc044dcfc21b5d8de8b9585291297cc349404198d6da6c15e9db3e95bd6ebd1dd177e379
|
7
|
+
data.tar.gz: 4ea0c6a415352f4e0d4edacdd8baac9a014d417a27c6a6100860c4e81a6d07d66970a8eceffc1d954d07157fa9364a7a8a6d546b1fde8c5d57f351926234e3d6
|
data/lib/hodmin/hodmin_tools.rb
CHANGED
@@ -106,10 +106,7 @@ class HomieDevice
|
|
106
106
|
+ ' check hodmin for updates'
|
107
107
|
end
|
108
108
|
mhash.tap { |hs| hs.delete('$homie') }
|
109
|
-
|
110
|
-
# ['$fw/name','$fw/version','$fw/checksum']
|
111
|
-
# Replace '/' by '_':
|
112
|
-
mhash.each { |k, v| create_attr(k.to_s.delete('$').gsub(/\//, '_').tr('-', '_'), v) }
|
109
|
+
mhash.each { |k, v| create_attr(k.to_s, v) }
|
113
110
|
|
114
111
|
# mac only downcase and without separating ':'
|
115
112
|
@mac = mac.delete(':').downcase
|
@@ -127,17 +124,15 @@ class HomieDevice
|
|
127
124
|
self.class.send(:define_method, name, &block)
|
128
125
|
end
|
129
126
|
|
130
|
-
# Helper to remove some special chars from string to avoid problems in instance_variable_set:
|
131
|
-
def remove_special_chars(str)
|
132
|
-
to_be_replaced = ['%', '!', '(', ')', '&', '?', ',', '.', '^', ' ']
|
133
|
-
to_be_replaced.each{|char| str.gsub!(char,'')}
|
134
|
-
str
|
135
|
-
end
|
136
|
-
|
137
127
|
# Helper to create instance variables on the fly:
|
138
128
|
def create_attr(name, value)
|
139
|
-
#
|
140
|
-
|
129
|
+
# Some topics-names of homie do not fit our needs due to special chars like '/'.
|
130
|
+
# ['$fw/name','$fw/version','$fw/checksum']
|
131
|
+
# to fix this, replace / delete some chars:
|
132
|
+
name = cleanup_instance_var_name(name)
|
133
|
+
# do we already have a instance variable with this name?
|
134
|
+
name = ensure_individual_instance_name(name, instance_variables)
|
135
|
+
# now name should be clean, we create an instancevariable using this name:
|
141
136
|
create_method(name.to_sym) { instance_variable_get('@' + name) }
|
142
137
|
instance_variable_set('@' + name, value)
|
143
138
|
end
|
@@ -218,7 +213,7 @@ end
|
|
218
213
|
|
219
214
|
# Reads all Homie-Devices from given broker.
|
220
215
|
# To be called with connected MQTT-client. Topic has to be set in calling program.
|
221
|
-
# Variable timeout_seconds defines, after what time
|
216
|
+
# Variable timeout_seconds defines, after what time our client.get will be cancelled. Choose
|
222
217
|
# a value high enough for your data, but fast enough for quick response. default is 0.7 sec,
|
223
218
|
# which should be enough for a lot of Homies controlled by a broker running on a Raspberry-PI.
|
224
219
|
def get_homies(client, *fw_list)
|
@@ -430,3 +425,38 @@ def default_config_initialize
|
|
430
425
|
config['ota'] = Hash['enabled' => true]
|
431
426
|
config
|
432
427
|
end
|
428
|
+
|
429
|
+
# Helper to remove some special chars from string to avoid problems in instance_variable_set:
|
430
|
+
def cleanup_instance_var_name(inputstring)
|
431
|
+
# translate some signs into char-representation:
|
432
|
+
str = inputstring
|
433
|
+
to_be_replaced = [['%','PCT'],[':','CLN'],['?','QMARK'],['&','AMPS'],['!','EXCLM'],['.','DOT']]
|
434
|
+
to_be_replaced.each{|org,rpl| str = str.gsub(org,'_' + rpl + '_')}
|
435
|
+
# translate some signs into '_':
|
436
|
+
str.tr!('/-','__')
|
437
|
+
# remove '$':
|
438
|
+
str.delete!('$')
|
439
|
+
# remove all other nonnumerical chars:
|
440
|
+
str.gsub!(/[^0-9a-zA-Z_]/i, '')
|
441
|
+
# sometimes remaining string may be empty:
|
442
|
+
str = 'GENERIC_TOPIC' if str.empty?
|
443
|
+
# return string as new instance variable name:
|
444
|
+
str
|
445
|
+
end
|
446
|
+
|
447
|
+
def ensure_individual_instance_name(name,list)
|
448
|
+
instance_variable_names = list.map do |i|
|
449
|
+
i = i.to_s
|
450
|
+
i[0] = '' if i[0] == '@'
|
451
|
+
i
|
452
|
+
end
|
453
|
+
n = 1
|
454
|
+
org_name = name
|
455
|
+
while instance_variable_names.include?(name)
|
456
|
+
# name already used, so change it a little bit:
|
457
|
+
name = org_name + '_' + n.to_s.rjust(3, "0")
|
458
|
+
n += 1
|
459
|
+
raise "ERR: Too many topics with special chars: #{instance_variable_names.join(', ')}" if n > 999
|
460
|
+
end
|
461
|
+
name
|
462
|
+
end
|
data/lib/hodmin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hodmin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Romeyke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: configatron
|