From e0c5b44994772f82cd334dbcdd039269ae65fde7 Mon Sep 17 00:00:00 2001 From: Khole Date: Mon, 16 Apr 2018 20:00:13 +0100 Subject: [PATCH] Hive R3 update (#13357) * Rebase * Update version number to 0.2.14 * Remove Blank Line * Added period to docstring * Update Tox Fix * Removed Lines --- .../components/binary_sensor/hive.py | 8 +++++ homeassistant/components/climate/hive.py | 13 +++++++ homeassistant/components/hive.py | 6 +++- homeassistant/components/light/hive.py | 8 +++++ homeassistant/components/sensor/hive.py | 34 ++++++++++++++++--- homeassistant/components/switch/hive.py | 8 +++++ requirements_all.txt | 2 +- 7 files changed, 72 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/binary_sensor/hive.py b/homeassistant/components/binary_sensor/hive.py index 2d4cbd8d070..46dd1b193e8 100644 --- a/homeassistant/components/binary_sensor/hive.py +++ b/homeassistant/components/binary_sensor/hive.py @@ -32,6 +32,7 @@ class HiveBinarySensorEntity(BinarySensorDevice): self.device_type = hivedevice["HA_DeviceType"] self.node_device_type = hivedevice["Hive_DeviceType"] self.session = hivesession + self.attributes = {} self.data_updatesource = '{}.{}'.format(self.device_type, self.node_id) @@ -52,6 +53,11 @@ class HiveBinarySensorEntity(BinarySensorDevice): """Return the name of the binary sensor.""" return self.node_name + @property + def device_state_attributes(self): + """Show Device Attributes.""" + return self.attributes + @property def is_on(self): """Return true if the binary sensor is on.""" @@ -61,3 +67,5 @@ class HiveBinarySensorEntity(BinarySensorDevice): def update(self): """Update all Node data from Hive.""" self.session.core.update_data(self.node_id) + self.attributes = self.session.attributes.state_attributes( + self.node_id) diff --git a/homeassistant/components/climate/hive.py b/homeassistant/components/climate/hive.py index 760ef131049..eb3aecae3a1 100644 --- a/homeassistant/components/climate/hive.py +++ b/homeassistant/components/climate/hive.py @@ -38,7 +38,10 @@ class HiveClimateEntity(ClimateDevice): self.node_id = hivedevice["Hive_NodeID"] self.node_name = hivedevice["Hive_NodeName"] self.device_type = hivedevice["HA_DeviceType"] + if self.device_type == "Heating": + self.thermostat_node_id = hivedevice["Thermostat_NodeID"] self.session = hivesession + self.attributes = {} self.data_updatesource = '{}.{}'.format(self.device_type, self.node_id) @@ -71,6 +74,11 @@ class HiveClimateEntity(ClimateDevice): friendly_name = "Hot Water" return friendly_name + @property + def device_state_attributes(self): + """Show Device Attributes.""" + return self.attributes + @property def temperature_unit(self): """Return the unit of measurement.""" @@ -175,4 +183,9 @@ class HiveClimateEntity(ClimateDevice): def update(self): """Update all Node data from Hive.""" + node = self.node_id + if self.device_type == "Heating": + node = self.thermostat_node_id + self.session.core.update_data(self.node_id) + self.attributes = self.session.attributes.state_attributes(node) diff --git a/homeassistant/components/hive.py b/homeassistant/components/hive.py index abe52ebe98a..aa662fc2fb6 100644 --- a/homeassistant/components/hive.py +++ b/homeassistant/components/hive.py @@ -12,7 +12,7 @@ from homeassistant.const import (CONF_PASSWORD, CONF_SCAN_INTERVAL, import homeassistant.helpers.config_validation as cv from homeassistant.helpers.discovery import load_platform -REQUIREMENTS = ['pyhiveapi==0.2.11'] +REQUIREMENTS = ['pyhiveapi==0.2.14'] _LOGGER = logging.getLogger(__name__) DOMAIN = 'hive' @@ -44,6 +44,8 @@ class HiveSession: light = None sensor = None switch = None + weather = None + attributes = None def setup(hass, config): @@ -70,6 +72,8 @@ def setup(hass, config): session.hotwater = Pyhiveapi.Hotwater() session.light = Pyhiveapi.Light() session.switch = Pyhiveapi.Switch() + session.weather = Pyhiveapi.Weather() + session.attributes = Pyhiveapi.Attributes() hass.data[DATA_HIVE] = session for ha_type, hive_type in DEVICETYPES.items(): diff --git a/homeassistant/components/light/hive.py b/homeassistant/components/light/hive.py index c4ecc5a9d2c..1fd9e8aaaca 100644 --- a/homeassistant/components/light/hive.py +++ b/homeassistant/components/light/hive.py @@ -34,6 +34,7 @@ class HiveDeviceLight(Light): self.device_type = hivedevice["HA_DeviceType"] self.light_device_type = hivedevice["Hive_Light_DeviceType"] self.session = hivesession + self.attributes = {} self.data_updatesource = '{}.{}'.format(self.device_type, self.node_id) self.session.entities.append(self) @@ -48,6 +49,11 @@ class HiveDeviceLight(Light): """Return the display name of this light.""" return self.node_name + @property + def device_state_attributes(self): + """Show Device Attributes.""" + return self.attributes + @property def brightness(self): """Brightness of the light (an integer in the range 1-255).""" @@ -136,3 +142,5 @@ class HiveDeviceLight(Light): def update(self): """Update all Node data from Hive.""" self.session.core.update_data(self.node_id) + self.attributes = self.session.attributes.state_attributes( + self.node_id) diff --git a/homeassistant/components/sensor/hive.py b/homeassistant/components/sensor/hive.py index cae2eaf7437..8f8ce2d1681 100644 --- a/homeassistant/components/sensor/hive.py +++ b/homeassistant/components/sensor/hive.py @@ -4,11 +4,17 @@ Support for the Hive devices. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/sensor.hive/ """ +from homeassistant.const import TEMP_CELSIUS from homeassistant.components.hive import DATA_HIVE from homeassistant.helpers.entity import Entity DEPENDENCIES = ['hive'] +FRIENDLY_NAMES = {'Hub_OnlineStatus': 'Hub Status', + 'Hive_OutsideTemperature': 'Outside Temperature'} +DEVICETYPE_ICONS = {'Hub_OnlineStatus': 'mdi:switch', + 'Hive_OutsideTemperature': 'mdi:thermometer'} + def setup_platform(hass, config, add_devices, discovery_info=None): """Set up Hive sensor devices.""" @@ -16,7 +22,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): return session = hass.data.get(DATA_HIVE) - if discovery_info["HA_DeviceType"] == "Hub_OnlineStatus": + if (discovery_info["HA_DeviceType"] == "Hub_OnlineStatus" or + discovery_info["HA_DeviceType"] == "Hive_OutsideTemperature"): add_devices([HiveSensorEntity(session, discovery_info)]) @@ -27,6 +34,7 @@ class HiveSensorEntity(Entity): """Initialize the sensor.""" self.node_id = hivedevice["Hive_NodeID"] self.device_type = hivedevice["HA_DeviceType"] + self.node_device_type = hivedevice["Hive_DeviceType"] self.session = hivesession self.data_updatesource = '{}.{}'.format(self.device_type, self.node_id) @@ -40,13 +48,29 @@ class HiveSensorEntity(Entity): @property def name(self): """Return the name of the sensor.""" - return "Hive hub status" + return FRIENDLY_NAMES.get(self.device_type) @property def state(self): """Return the state of the sensor.""" - return self.session.sensor.hub_online_status(self.node_id) + if self.device_type == "Hub_OnlineStatus": + return self.session.sensor.hub_online_status(self.node_id) + elif self.device_type == "Hive_OutsideTemperature": + return self.session.weather.temperature() + + @property + def unit_of_measurement(self): + """Return the unit of measurement.""" + if self.device_type == "Hive_OutsideTemperature": + return TEMP_CELSIUS + + @property + def icon(self): + """Return the icon to use.""" + return DEVICETYPE_ICONS.get(self.device_type) def update(self): - """Update all Node data from Hive.""" - self.session.core.update_data(self.node_id) + """Update all Node data frome Hive.""" + if self.session.core.update_data(self.node_id): + for entity in self.session.entities: + entity.handle_update(self.data_updatesource) diff --git a/homeassistant/components/switch/hive.py b/homeassistant/components/switch/hive.py index 67ebe95ba8e..49fc9696b5e 100644 --- a/homeassistant/components/switch/hive.py +++ b/homeassistant/components/switch/hive.py @@ -28,6 +28,7 @@ class HiveDevicePlug(SwitchDevice): self.node_name = hivedevice["Hive_NodeName"] self.device_type = hivedevice["HA_DeviceType"] self.session = hivesession + self.attributes = {} self.data_updatesource = '{}.{}'.format(self.device_type, self.node_id) self.session.entities.append(self) @@ -42,6 +43,11 @@ class HiveDevicePlug(SwitchDevice): """Return the name of this Switch device if any.""" return self.node_name + @property + def device_state_attributes(self): + """Show Device Attributes.""" + return self.attributes + @property def current_power_w(self): """Return the current power usage in W.""" @@ -67,3 +73,5 @@ class HiveDevicePlug(SwitchDevice): def update(self): """Update all Node data from Hive.""" self.session.core.update_data(self.node_id) + self.attributes = self.session.attributes.state_attributes( + self.node_id) diff --git a/requirements_all.txt b/requirements_all.txt index 9772cf87a44..fe82942cab8 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -777,7 +777,7 @@ pyharmony==1.0.20 pyhik==0.1.8 # homeassistant.components.hive -pyhiveapi==0.2.11 +pyhiveapi==0.2.14 # homeassistant.components.homematic pyhomematic==0.1.41