Fix mysensors callback (#7057)

* Fix mysensors callback

* All messages was not triggering proper updates. Fix by checking all
  child value types each update.

* Upgrade mysensors dep

* Fix pickle persistence when upgrading.
This commit is contained in:
Martin Hjelmare 2017-04-12 04:17:09 +02:00 committed by Paulus Schoutsen
parent ed012014bc
commit 4e388666b2
3 changed files with 56 additions and 56 deletions

View File

@ -20,22 +20,24 @@ def setup_scanner(hass, config, see, discovery_info=None):
"""Callback for mysensors platform.""" """Callback for mysensors platform."""
node = gateway.sensors[msg.node_id] node = gateway.sensors[msg.node_id]
if node.sketch_name is None: if node.sketch_name is None:
_LOGGER.info('No sketch_name: node %s', msg.node_id) _LOGGER.debug('No sketch_name: node %s', msg.node_id)
return return
pres = gateway.const.Presentation pres = gateway.const.Presentation
set_req = gateway.const.SetReq set_req = gateway.const.SetReq
for child in node.children.values(): child = node.children.get(msg.child_id)
if child is None:
return
position = child.values.get(set_req.V_POSITION) position = child.values.get(set_req.V_POSITION)
if child.type != pres.S_GPS or position is None: if child.type != pres.S_GPS or position is None:
continue return
try: try:
latitude, longitude, _ = position.split(',') latitude, longitude, _ = position.split(',')
except ValueError: except ValueError:
_LOGGER.error('Payload for V_POSITION %s is not of format ' _LOGGER.error('Payload for V_POSITION %s is not of format '
'latitude,longitude,altitude', position) 'latitude,longitude,altitude', position)
continue return
name = '{} {} {}'.format( name = '{} {} {}'.format(
node.sketch_name, msg.node_id, child.id) node.sketch_name, msg.node_id, child.id)
attr = { attr = {

View File

@ -46,7 +46,7 @@ MYSENSORS_GATEWAYS = 'mysensors_gateways'
MQTT_COMPONENT = 'mqtt' MQTT_COMPONENT = 'mqtt'
REQUIREMENTS = [ REQUIREMENTS = [
'https://github.com/theolind/pymysensors/archive/' 'https://github.com/theolind/pymysensors/archive/'
'ff3476b70edc9c995b939cddb9d51f8d2d018581.zip#pymysensors==0.9.0'] 'c6990eaaa741444a638608e6e00488195e2ca74c.zip#pymysensors==0.9.1']
def is_socket_address(value): def is_socket_address(value):
@ -206,11 +206,8 @@ def setup(hass, config):
for node_id in gateway.sensors: for node_id in gateway.sensors:
node = gateway.sensors[node_id] node = gateway.sensors[node_id]
for child_id in node.children: for child_id in node.children:
child = node.children[child_id]
for value_type in child.values:
msg = mysensors.Message().modify( msg = mysensors.Message().modify(
node_id=node_id, child_id=child_id, type=1, node_id=node_id, child_id=child_id)
sub_type=value_type)
gateway.event_callback(msg) gateway.event_callback(msg)
gateway.start() gateway.start()
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP,
@ -274,18 +271,19 @@ def pf_callback_factory(map_sv_types, devices, entity_class, add_devices=None):
_LOGGER.debug('No sketch_name: node %s', msg.node_id) _LOGGER.debug('No sketch_name: node %s', msg.node_id)
return return
child = gateway.sensors[msg.node_id].children.get(msg.child_id) child = gateway.sensors[msg.node_id].children.get(msg.child_id)
if child is None or child.values.get(msg.sub_type) is None: if child is None:
return return
key = msg.node_id, child.id, msg.sub_type for value_type in child.values:
key = msg.node_id, child.id, value_type
if child.type not in map_sv_types or \ if child.type not in map_sv_types or \
msg.sub_type not in map_sv_types[child.type]: value_type not in map_sv_types[child.type]:
return continue
if key in devices: if key in devices:
if add_devices: if add_devices:
devices[key].schedule_update_ha_state(True) devices[key].schedule_update_ha_state(True)
else: else:
devices[key].update() devices[key].update()
return continue
name = '{} {} {}'.format( name = '{} {} {}'.format(
gateway.sensors[msg.node_id].sketch_name, msg.node_id, gateway.sensors[msg.node_id].sketch_name, msg.node_id,
child.id) child.id)
@ -294,7 +292,7 @@ def pf_callback_factory(map_sv_types, devices, entity_class, add_devices=None):
else: else:
device_class = entity_class device_class = entity_class
devices[key] = device_class( devices[key] = device_class(
gateway, msg.node_id, child.id, name, msg.sub_type) gateway, msg.node_id, child.id, name, value_type)
if add_devices: if add_devices:
_LOGGER.info('Adding new devices: %s', [devices[key]]) _LOGGER.info('Adding new devices: %s', [devices[key]])
add_devices([devices[key]], True) add_devices([devices[key]], True)

View File

@ -314,7 +314,7 @@ https://github.com/tfriedel/python-lightify/archive/d6eadcf311e6e21746182d1480e9
https://github.com/thecynic/pylutron/archive/v0.1.0.zip#pylutron==0.1.0 https://github.com/thecynic/pylutron/archive/v0.1.0.zip#pylutron==0.1.0
# homeassistant.components.mysensors # homeassistant.components.mysensors
https://github.com/theolind/pymysensors/archive/ff3476b70edc9c995b939cddb9d51f8d2d018581.zip#pymysensors==0.9.0 https://github.com/theolind/pymysensors/archive/c6990eaaa741444a638608e6e00488195e2ca74c.zip#pymysensors==0.9.1
# homeassistant.components.sensor.modem_callerid # homeassistant.components.sensor.modem_callerid
https://github.com/vroomfonde1/basicmodem/archive/0.7.zip#basicmodem==0.7 https://github.com/vroomfonde1/basicmodem/archive/0.7.zip#basicmodem==0.7