@@ -302,10 +302,10 @@ def SensorsInfo(self):
302
302
'DigitalActuator' : {'function' : 'read' , 'data_args' : {'type' : 'digital_actuator' , 'unit' : 'd' }},
303
303
'AnalogSensor' : {'function' : 'readFloat' , 'data_args' : {'type' : 'analog_sensor' }},
304
304
'AnalogActuator' : {'function' : 'readFloat' , 'data_args' : {'type' : 'analog_actuator' }}}
305
- extension_types = {'ADC' : {'function' : 'analogReadAllFloat' },
306
- 'DAC' : {'function' : 'analogReadAllFloat' },
307
- 'PWM' : {'function' : 'pwmWildcard' },
308
- 'GPIOPort' : {'function' : 'wildcard' }}
305
+ # extension_types = {'ADC': {'function': 'analogReadAllFloat'},
306
+ # 'DAC': {'function': 'analogReadAllFloat'},
307
+ # 'PWM': {'function': 'pwmWildcard'},
308
+ # 'GPIOPort': {'function': 'wildcard'}}
309
309
for device_type in device ['type' ]:
310
310
try :
311
311
display_name = device ['description' ]
@@ -319,19 +319,22 @@ def SensorsInfo(self):
319
319
channel = '{}:{}' .format (device ['name' ], device_type .lower ())
320
320
else :
321
321
channel = device ['name' ]
322
- cayennemqtt .DataChannel .add (sensors_info , cayennemqtt .DEV_SENSOR , channel , value = self .CallDeviceFunction (func ), name = display_name , ** sensor_type ['data_args' ])
322
+ value = self .CallDeviceFunction (func )
323
+ cayennemqtt .DataChannel .add (sensors_info , cayennemqtt .DEV_SENSOR , channel , value = value , name = display_name , ** sensor_type ['data_args' ])
324
+ if 'DigitalActuator' == device_type and value in (0 , 1 ):
325
+ manager .updateDeviceState (device ['name' ], value )
323
326
except :
324
327
exception ('Failed to get sensor data: {} {}' .format (device_type , device ['name' ]))
325
- else :
326
- try :
327
- extension_type = extension_types [device_type ]
328
- func = getattr (sensor , extension_type ['function' ])
329
- values = self .CallDeviceFunction (func )
330
- for pin , value in values .items ():
331
- cayennemqtt .DataChannel .add (sensors_info , cayennemqtt .DEV_SENSOR , device ['name' ] + ':' + str (pin ), cayennemqtt .VALUE , value , name = display_name )
332
- except :
333
- exception ('Failed to get extension data: {} {}' .format (device_type , device ['name' ]))
334
- logJson ('Sensors info: {}' .format (sensors_info ))
328
+ # else:
329
+ # try:
330
+ # extension_type = extension_types[device_type]
331
+ # func = getattr(sensor, extension_type['function'])
332
+ # values = self.CallDeviceFunction(func)
333
+ # for pin, value in values.items():
334
+ # cayennemqtt.DataChannel.add(sensors_info, cayennemqtt.DEV_SENSOR, device['name'] + ':' + str(pin), cayennemqtt.VALUE, value, name=display_name)
335
+ # except:
336
+ # exception('Failed to get extension data: {} {}'.format(device_type, device['name']))
337
+ info ('Sensors info: {}' .format (sensors_info ))
335
338
return sensors_info
336
339
337
340
def AddSensor (self , name , description , device , args ):
@@ -523,13 +526,16 @@ def SensorCommand(self, command, sensorId, channel, value):
523
526
info ('Sensor not found' )
524
527
return result
525
528
if command in commands :
526
- info ('Sensor found: {}' .format (instance .DEVICES [sensorId ]))
529
+ device = instance .DEVICES [sensorId ]
530
+ info ('Sensor found: {}' .format (device ))
527
531
func = getattr (sensor , commands [command ]['function' ])
528
532
value = commands [command ]['value_type' ](value )
529
533
if channel :
530
534
result = self .CallDeviceFunction (func , int (channel ), value )
531
535
else :
532
536
result = self .CallDeviceFunction (func , value )
537
+ if 'DigitalActuator' in device ['type' ]:
538
+ manager .updateDeviceState (sensorId , value )
533
539
return result
534
540
warn ('Command not implemented: {}' .format (command ))
535
541
return result
0 commit comments