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,5 @@
"""Support for Genius Hub sensor devices."""
from datetime import timedelta
import logging
from homeassistant.const import DEVICE_CLASS_BATTERY
from homeassistant.core import callback
@ -10,8 +9,6 @@ from homeassistant.util.dt import utc_from_timestamp, utcnow
from . import DOMAIN
_LOGGER = logging.getLogger(__name__)
GH_HAS_BATTERY = ["Room Thermostat", "Genius Valve", "Room Sensor", "Radiator Valve"]
GH_LEVEL_MAPPING = {
@ -26,17 +23,16 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
client = hass.data[DOMAIN]["client"]
sensors = [
GeniusDevice(client, d)
GeniusBattery(client, d)
for d in client.hub.device_objs
if d.type in GH_HAS_BATTERY
]
issues = [GeniusIssue(client, i) for i in list(GH_LEVEL_MAPPING)]
async_add_entities(sensors + issues, update_before_add=True)
class GeniusDevice(Entity):
class GeniusBattery(Entity):
"""Representation of a Genius Hub sensor."""
def __init__(self, client, device):
@ -63,7 +59,7 @@ class GeniusDevice(Entity):
def icon(self):
"""Return the icon of the sensor."""
# noqa; pylint: disable=protected-access
values = self._device._raw_json["childValues"]
values = self._device._raw_data["childValues"]
last_comms = utc_from_timestamp(values["lastComms"]["val"])
if "WakeUp_Interval" in values:
@ -74,7 +70,7 @@ class GeniusDevice(Entity):
if last_comms < utcnow() - interval * 3:
return "mdi:battery-unknown"
battery_level = self._device.state["batteryLevel"]
battery_level = self._device.data["state"]["batteryLevel"]
if battery_level == 255:
return "mdi:battery-unknown"
if battery_level < 40:
@ -104,17 +100,17 @@ class GeniusDevice(Entity):
@property
def state(self):
"""Return the state of the sensor."""
level = self._device.state.get("batteryLevel", 255)
level = self._device.data["state"].get("batteryLevel", 255)
return level if level != 255 else 0
@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"]
attrs["last_comms"] = utc_from_timestamp(last_comms).isoformat()
return {**attrs}