Add hive boost to climate and water_heater (#26789)
* Start the Boost work * Add services.yaml * Added Services #2 * Start the Boost work * Add services.yaml * Added Services #2 * Working Services * pyhiveapi to 0.2.19 * Update Libary to 0.2.19 * Update Water_heater boost * Added Async hass add function * Update Services * Reviewed Changes * Fixed Refresh System * Review 2 * Moved device iteration to the platform * update * Updates #2 * Review#3 New Base Class * Review #5 * Update homeassistant/components/hive/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@kth.se> * Update homeassistant/components/hive/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@kth.se> * Update homeassistant/components/hive/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@kth.se> * Review 6 * Review 7 * Removed Child classes to inhertit from the parent
This commit is contained in:
parent
58446c79fc
commit
fc3f5163f1
10 changed files with 218 additions and 187 deletions
|
@ -2,7 +2,7 @@
|
|||
from homeassistant.const import TEMP_CELSIUS
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from . import DATA_HIVE, DOMAIN
|
||||
from . import DOMAIN, DATA_HIVE, HiveEntity
|
||||
|
||||
FRIENDLY_NAMES = {
|
||||
"Hub_OnlineStatus": "Hive Hub Status",
|
||||
|
@ -19,28 +19,18 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
"""Set up Hive sensor devices."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
||||
session = hass.data.get(DATA_HIVE)
|
||||
|
||||
if (
|
||||
discovery_info["HA_DeviceType"] == "Hub_OnlineStatus"
|
||||
or discovery_info["HA_DeviceType"] == "Hive_OutsideTemperature"
|
||||
):
|
||||
add_entities([HiveSensorEntity(session, discovery_info)])
|
||||
devs = []
|
||||
for dev in discovery_info:
|
||||
if dev["HA_DeviceType"] in FRIENDLY_NAMES:
|
||||
devs.append(HiveSensorEntity(session, dev))
|
||||
add_entities(devs)
|
||||
|
||||
|
||||
class HiveSensorEntity(Entity):
|
||||
class HiveSensorEntity(HiveEntity, Entity):
|
||||
"""Hive Sensor Entity."""
|
||||
|
||||
def __init__(self, hivesession, hivedevice):
|
||||
"""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 = f"{self.device_type}.{self.node_id}"
|
||||
self._unique_id = f"{self.node_id}-{self.device_type}"
|
||||
self.session.entities.append(self)
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return unique ID of entity."""
|
||||
|
@ -51,11 +41,6 @@ class HiveSensorEntity(Entity):
|
|||
"""Return device information."""
|
||||
return {"identifiers": {(DOMAIN, self.unique_id)}, "name": self.name}
|
||||
|
||||
def handle_update(self, updatesource):
|
||||
"""Handle the new update request."""
|
||||
if f"{self.device_type}.{self.node_id}" not in updatesource:
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
|
@ -82,6 +67,4 @@ class HiveSensorEntity(Entity):
|
|||
|
||||
def update(self):
|
||||
"""Update all Node data from Hive."""
|
||||
if self.session.core.update_data(self.node_id):
|
||||
for entity in self.session.entities:
|
||||
entity.handle_update(self.data_updatesource)
|
||||
self.session.core.update_data(self.node_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue