Fix bug and bump geniushub client (#25599)

Fix bug, delint and bump client
This commit is contained in:
David Bonnes 2019-07-31 18:44:09 +01:00 committed by GitHub
parent 8ffc6c05b7
commit 16a98359c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 11 deletions

View file

@ -63,7 +63,7 @@ async def async_setup(hass, hass_config):
hass.async_create_task(async_load_platform( hass.async_create_task(async_load_platform(
hass, platform, DOMAIN, {}, hass_config)) hass, platform, DOMAIN, {}, hass_config))
if not data._client._api_v1: # pylint: disable=protected-access if data._client.api_version == 3: # pylint: disable=protected-access
for platform in ['sensor', 'binary_sensor']: for platform in ['sensor', 'binary_sensor']:
hass.async_create_task(async_load_platform( hass.async_create_task(async_load_platform(
hass, platform, DOMAIN, {}, hass_config)) hass, platform, DOMAIN, {}, hass_config))

View file

@ -1,10 +1,10 @@
"""Support for Genius Hub binary_sensor devices.""" """Support for Genius Hub binary_sensor devices."""
from datetime import datetime
import logging import logging
from homeassistant.components.binary_sensor import BinarySensorDevice from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.util.dt import utc_from_timestamp
from . import DOMAIN from . import DOMAIN
@ -67,9 +67,8 @@ class GeniusBinarySensor(BinarySensorDevice):
attrs = {} attrs = {}
attrs['assigned_zone'] = self._device.assignedZones[0]['name'] attrs['assigned_zone'] = self._device.assignedZones[0]['name']
last_comms = self._device._info_raw['childValues']['lastComms']['val'] # noqa; pylint: disable=protected-access last_comms = self._device._raw_json['childValues']['lastComms']['val'] # noqa; pylint: disable=protected-access
if last_comms != 0: if last_comms != 0:
attrs['last_comms'] = datetime.utcfromtimestamp( attrs['last_comms'] = utc_from_timestamp(last_comms).isoformat()
last_comms).isoformat()
return {**attrs} return {**attrs}

View file

@ -3,7 +3,7 @@
"name": "Genius Hub", "name": "Genius Hub",
"documentation": "https://www.home-assistant.io/components/geniushub", "documentation": "https://www.home-assistant.io/components/geniushub",
"requirements": [ "requirements": [
"geniushub-client==0.5.00" "geniushub-client==0.5.4"
], ],
"dependencies": [], "dependencies": [],
"codeowners": ["@zxdavb"] "codeowners": ["@zxdavb"]

View file

@ -62,10 +62,13 @@ class GeniusDevice(Entity):
@property @property
def icon(self): def icon(self):
"""Return the icon of the sensor.""" """Return the icon of the sensor."""
values = self._device._info_raw['childValues'] # noqa; pylint: disable=protected-access values = self._device._raw_json['childValues'] # noqa; pylint: disable=protected-access
last_comms = utc_from_timestamp(values['lastComms']['val']) last_comms = utc_from_timestamp(values['lastComms']['val'])
interval = timedelta(seconds=values['WakeUp_Interval']['val']) if 'WakeUp_Interval' in values:
interval = timedelta(seconds=values['WakeUp_Interval']['val'])
else:
interval = timedelta(minutes=20)
if last_comms < utcnow() - interval * 3: if last_comms < utcnow() - interval * 3:
return 'mdi:battery-unknown' return 'mdi:battery-unknown'
@ -100,7 +103,7 @@ class GeniusDevice(Entity):
@property @property
def state(self): def state(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
level = self._device.state['batteryLevel'] level = self._device.state.get('batteryLevel', 255)
return level if level != 255 else 0 return level if level != 255 else 0
@property @property
@ -109,7 +112,7 @@ class GeniusDevice(Entity):
attrs = {} attrs = {}
attrs['assigned_zone'] = self._device.assignedZones[0]['name'] attrs['assigned_zone'] = self._device.assignedZones[0]['name']
last_comms = self._device._info_raw['childValues']['lastComms']['val'] # noqa; pylint: disable=protected-access last_comms = self._device._raw_json['childValues']['lastComms']['val'] # noqa; pylint: disable=protected-access
attrs['last_comms'] = utc_from_timestamp(last_comms).isoformat() attrs['last_comms'] = utc_from_timestamp(last_comms).isoformat()
return {**attrs} return {**attrs}

View file

@ -517,7 +517,7 @@ gearbest_parser==1.0.7
geizhals==0.0.9 geizhals==0.0.9
# homeassistant.components.geniushub # homeassistant.components.geniushub
geniushub-client==0.5.00 geniushub-client==0.5.4
# homeassistant.components.geo_json_events # homeassistant.components.geo_json_events
# homeassistant.components.nsw_rural_fire_service_feed # homeassistant.components.nsw_rural_fire_service_feed