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
|
@ -5,13 +5,14 @@ from homeassistant.components.climate.const import (
|
|||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_OFF,
|
||||
PRESET_BOOST,
|
||||
PRESET_NONE,
|
||||
SUPPORT_PRESET_MODE,
|
||||
SUPPORT_TARGET_TEMPERATURE,
|
||||
PRESET_NONE,
|
||||
)
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||
|
||||
from . import DATA_HIVE, DOMAIN
|
||||
|
||||
from . import DOMAIN, DATA_HIVE, HiveEntity, refresh_system
|
||||
|
||||
HIVE_TO_HASS_STATE = {
|
||||
"SCHEDULE": HVAC_MODE_AUTO,
|
||||
|
@ -34,28 +35,21 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
"""Set up Hive climate devices."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
if discovery_info["HA_DeviceType"] != "Heating":
|
||||
return
|
||||
|
||||
session = hass.data.get(DATA_HIVE)
|
||||
climate = HiveClimateEntity(session, discovery_info)
|
||||
|
||||
add_entities([climate])
|
||||
devs = []
|
||||
for dev in discovery_info:
|
||||
devs.append(HiveClimateEntity(session, dev))
|
||||
add_entities(devs)
|
||||
|
||||
|
||||
class HiveClimateEntity(ClimateDevice):
|
||||
class HiveClimateEntity(HiveEntity, ClimateDevice):
|
||||
"""Hive Climate Device."""
|
||||
|
||||
def __init__(self, hivesession, hivedevice):
|
||||
def __init__(self, hive_session, hive_device):
|
||||
"""Initialize the Climate device."""
|
||||
self.node_id = hivedevice["Hive_NodeID"]
|
||||
self.node_name = hivedevice["Hive_NodeName"]
|
||||
self.device_type = hivedevice["HA_DeviceType"]
|
||||
self.thermostat_node_id = hivedevice["Thermostat_NodeID"]
|
||||
self.session = hivesession
|
||||
self.attributes = {}
|
||||
self.data_updatesource = f"{self.device_type}.{self.node_id}"
|
||||
self._unique_id = f"{self.node_id}-{self.device_type}"
|
||||
super().__init__(hive_session, hive_device)
|
||||
self.thermostat_node_id = hive_device["Thermostat_NodeID"]
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
|
@ -72,11 +66,6 @@ class HiveClimateEntity(ClimateDevice):
|
|||
"""Return the list of supported features."""
|
||||
return SUPPORT_FLAGS
|
||||
|
||||
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 Climate device."""
|
||||
|
@ -99,7 +88,7 @@ class HiveClimateEntity(ClimateDevice):
|
|||
return SUPPORT_HVAC
|
||||
|
||||
@property
|
||||
def hvac_mode(self) -> str:
|
||||
def hvac_mode(self):
|
||||
"""Return hvac operation ie. heat, cool mode.
|
||||
|
||||
Need to be one of HVAC_MODE_*.
|
||||
|
@ -143,43 +132,29 @@ class HiveClimateEntity(ClimateDevice):
|
|||
"""Return a list of available preset modes."""
|
||||
return SUPPORT_PRESET
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""When entity is added to Home Assistant."""
|
||||
await super().async_added_to_hass()
|
||||
self.session.entities.append(self)
|
||||
|
||||
@refresh_system
|
||||
def set_hvac_mode(self, hvac_mode):
|
||||
"""Set new target hvac mode."""
|
||||
new_mode = HASS_TO_HIVE_STATE[hvac_mode]
|
||||
self.session.heating.set_mode(self.node_id, new_mode)
|
||||
|
||||
for entity in self.session.entities:
|
||||
entity.handle_update(self.data_updatesource)
|
||||
|
||||
@refresh_system
|
||||
def set_temperature(self, **kwargs):
|
||||
"""Set new target temperature."""
|
||||
new_temperature = kwargs.get(ATTR_TEMPERATURE)
|
||||
if new_temperature is not None:
|
||||
self.session.heating.set_target_temperature(self.node_id, new_temperature)
|
||||
|
||||
for entity in self.session.entities:
|
||||
entity.handle_update(self.data_updatesource)
|
||||
|
||||
def set_preset_mode(self, preset_mode) -> None:
|
||||
@refresh_system
|
||||
def set_preset_mode(self, preset_mode):
|
||||
"""Set new preset mode."""
|
||||
if preset_mode == PRESET_NONE and self.preset_mode == PRESET_BOOST:
|
||||
self.session.heating.turn_boost_off(self.node_id)
|
||||
|
||||
elif preset_mode == PRESET_BOOST:
|
||||
curtemp = self.session.heating.current_temperature(self.node_id)
|
||||
curtemp = round(curtemp * 2) / 2
|
||||
curtemp = round(self.current_temperature * 2) / 2
|
||||
temperature = curtemp + 0.5
|
||||
|
||||
self.session.heating.turn_boost_on(self.node_id, 30, temperature)
|
||||
|
||||
for entity in self.session.entities:
|
||||
entity.handle_update(self.data_updatesource)
|
||||
|
||||
def update(self):
|
||||
"""Update all Node data from Hive."""
|
||||
self.session.core.update_data(self.node_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue