Hotfix for crash with virtual devices (#18808)
* Quickfix for crash with virtual devices Added try/except to critical loops of processing Reinforced read_devices, map_device_to_type and update processing * oopspull/18811/head
parent
31d7221c90
commit
0467d0563a
|
@ -103,29 +103,31 @@ class FibaroController():
|
||||||
"""Handle change report received from the HomeCenter."""
|
"""Handle change report received from the HomeCenter."""
|
||||||
callback_set = set()
|
callback_set = set()
|
||||||
for change in state.get('changes', []):
|
for change in state.get('changes', []):
|
||||||
|
try:
|
||||||
dev_id = change.pop('id')
|
dev_id = change.pop('id')
|
||||||
|
if dev_id not in self._device_map.keys():
|
||||||
|
continue
|
||||||
|
device = self._device_map[dev_id]
|
||||||
for property_name, value in change.items():
|
for property_name, value in change.items():
|
||||||
if property_name == 'log':
|
if property_name == 'log':
|
||||||
if value and value != "transfer OK":
|
if value and value != "transfer OK":
|
||||||
_LOGGER.debug("LOG %s: %s",
|
_LOGGER.debug("LOG %s: %s",
|
||||||
self._device_map[dev_id].friendly_name,
|
device.friendly_name, value)
|
||||||
value)
|
|
||||||
continue
|
continue
|
||||||
if property_name == 'logTemp':
|
if property_name == 'logTemp':
|
||||||
continue
|
continue
|
||||||
if property_name in self._device_map[dev_id].properties:
|
if property_name in device.properties:
|
||||||
self._device_map[dev_id].properties[property_name] = \
|
device.properties[property_name] = \
|
||||||
value
|
value
|
||||||
_LOGGER.debug("<- %s.%s = %s",
|
_LOGGER.debug("<- %s.%s = %s", device.ha_id,
|
||||||
self._device_map[dev_id].ha_id,
|
property_name, str(value))
|
||||||
property_name,
|
|
||||||
str(value))
|
|
||||||
else:
|
else:
|
||||||
_LOGGER.warning("Error updating %s data of %s, not found",
|
_LOGGER.warning("%s.%s not found", device.ha_id,
|
||||||
property_name,
|
property_name)
|
||||||
self._device_map[dev_id].ha_id)
|
|
||||||
if dev_id in self._callbacks:
|
if dev_id in self._callbacks:
|
||||||
callback_set.add(dev_id)
|
callback_set.add(dev_id)
|
||||||
|
except (ValueError, KeyError):
|
||||||
|
pass
|
||||||
for item in callback_set:
|
for item in callback_set:
|
||||||
self._callbacks[item]()
|
self._callbacks[item]()
|
||||||
|
|
||||||
|
@ -137,8 +139,12 @@ class FibaroController():
|
||||||
def _map_device_to_type(device):
|
def _map_device_to_type(device):
|
||||||
"""Map device to HA device type."""
|
"""Map device to HA device type."""
|
||||||
# Use our lookup table to identify device type
|
# Use our lookup table to identify device type
|
||||||
device_type = FIBARO_TYPEMAP.get(
|
if 'type' in device:
|
||||||
device.type, FIBARO_TYPEMAP.get(device.baseType))
|
device_type = FIBARO_TYPEMAP.get(device.type)
|
||||||
|
elif 'baseType' in device:
|
||||||
|
device_type = FIBARO_TYPEMAP.get(device.baseType)
|
||||||
|
else:
|
||||||
|
device_type = None
|
||||||
|
|
||||||
# We can also identify device type by its capabilities
|
# We can also identify device type by its capabilities
|
||||||
if device_type is None:
|
if device_type is None:
|
||||||
|
@ -156,8 +162,7 @@ class FibaroController():
|
||||||
|
|
||||||
# Switches that control lights should show up as lights
|
# Switches that control lights should show up as lights
|
||||||
if device_type == 'switch' and \
|
if device_type == 'switch' and \
|
||||||
'isLight' in device.properties and \
|
device.properties.get('isLight', 'false') == 'true':
|
||||||
device.properties.isLight == 'true':
|
|
||||||
device_type = 'light'
|
device_type = 'light'
|
||||||
return device_type
|
return device_type
|
||||||
|
|
||||||
|
@ -165,7 +170,9 @@ class FibaroController():
|
||||||
"""Read and process the device list."""
|
"""Read and process the device list."""
|
||||||
devices = self._client.devices.list()
|
devices = self._client.devices.list()
|
||||||
self._device_map = {}
|
self._device_map = {}
|
||||||
|
self.fibaro_devices = defaultdict(list)
|
||||||
for device in devices:
|
for device in devices:
|
||||||
|
try:
|
||||||
if device.roomID == 0:
|
if device.roomID == 0:
|
||||||
room_name = 'Unknown'
|
room_name = 'Unknown'
|
||||||
else:
|
else:
|
||||||
|
@ -173,18 +180,21 @@ class FibaroController():
|
||||||
device.friendly_name = room_name + ' ' + device.name
|
device.friendly_name = room_name + ' ' + device.name
|
||||||
device.ha_id = '{}_{}_{}'.format(
|
device.ha_id = '{}_{}_{}'.format(
|
||||||
slugify(room_name), slugify(device.name), device.id)
|
slugify(room_name), slugify(device.name), device.id)
|
||||||
self._device_map[device.id] = device
|
|
||||||
self.fibaro_devices = defaultdict(list)
|
|
||||||
for device in self._device_map.values():
|
|
||||||
if device.enabled and \
|
if device.enabled and \
|
||||||
(not device.isPlugin or self._import_plugins):
|
('isPlugin' not in device or
|
||||||
|
(not device.isPlugin or self._import_plugins)):
|
||||||
device.mapped_type = self._map_device_to_type(device)
|
device.mapped_type = self._map_device_to_type(device)
|
||||||
|
else:
|
||||||
|
device.mapped_type = None
|
||||||
if device.mapped_type:
|
if device.mapped_type:
|
||||||
|
self._device_map[device.id] = device
|
||||||
self.fibaro_devices[device.mapped_type].append(device)
|
self.fibaro_devices[device.mapped_type].append(device)
|
||||||
else:
|
else:
|
||||||
_LOGGER.debug("%s (%s, %s) not mapped",
|
_LOGGER.debug("%s (%s, %s) not used",
|
||||||
device.ha_id, device.type,
|
device.ha_id, device.type,
|
||||||
device.baseType)
|
device.baseType)
|
||||||
|
except (KeyError, ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
|
|
Loading…
Reference in New Issue