Bump geniushub client, handle dead devices, handle raise_for_status (#25687)

* Initial commit

* tweak error logging

* bump client

* correct regression

* small coding tweak

* debug logging to one entry

* refactor for self.data['attr']

* bump client

* small tidy-up
This commit is contained in:
David Bonnes 2019-08-04 23:06:36 +01:00 committed by Martin Hjelmare
parent 0d95ad3857
commit b0c79c271d
7 changed files with 50 additions and 79 deletions

View file

@ -1,6 +1,4 @@
"""Support for Genius Hub binary_sensor devices."""
import logging
from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -8,8 +6,6 @@ from homeassistant.util.dt import utc_from_timestamp
from . import DOMAIN
_LOGGER = logging.getLogger(__name__)
GH_IS_SWITCH = ["Dual Channel Receiver", "Electric Switch", "Smart Plug"]
@ -17,9 +13,10 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
"""Set up the Genius Hub sensor entities."""
client = hass.data[DOMAIN]["client"]
devices = [d for d in client.hub.device_objs if d.type is not None]
switches = [
GeniusBinarySensor(client, d) for d in devices if d.type[:21] in GH_IS_SWITCH
GeniusBinarySensor(client, d)
for d in client.hub.device_objs
if d.type[:21] in GH_IS_SWITCH
]
async_add_entities(switches)
@ -59,16 +56,16 @@ class GeniusBinarySensor(BinarySensorDevice):
@property
def is_on(self):
"""Return the status of the sensor."""
return self._device.state["outputOnOff"]
return self._device.data["state"]["outputOnOff"]
@property
def device_state_attributes(self):
"""Return the device state attributes."""
attrs = {}
attrs["assigned_zone"] = self._device.assignedZones[0]["name"]
attrs["assigned_zone"] = self._device.data["assignedZones"][0]["name"]
# noqa; pylint: disable=protected-access
last_comms = self._device._raw_json["childValues"]["lastComms"]["val"]
last_comms = self._device._raw_data["childValues"]["lastComms"]["val"]
if last_comms != 0:
attrs["last_comms"] = utc_from_timestamp(last_comms).isoformat()