Hive R3 update (#13357)

* Rebase

* Update version number to 0.2.14

* Remove Blank Line

* Added period to docstring

* Update Tox Fix

* Removed Lines
This commit is contained in:
Khole 2018-04-16 20:00:13 +01:00 committed by Martin Hjelmare
parent 595600dea5
commit e0c5b44994
7 changed files with 72 additions and 7 deletions

View file

@ -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)