Refactor hive entity (#72311)

* Add hive category entity changes

* Updates based on PR feedback

* Revert libary bump

* Update after PR feedback

* Update Binary device class for smoke sensor

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Remove entity category

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Updates after PR review

* Remove unused import

* Update light based on PR feedback

* Update light code from PR review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Khole 2022-05-29 11:08:50 +01:00 committed by GitHub
parent e7e48cd9f6
commit d59ecc4c96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 152 additions and 402 deletions

View file

@ -16,7 +16,6 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import HiveEntity, refresh_system
@ -46,8 +45,6 @@ HIVE_TO_HASS_HVAC_ACTION = {
}
TEMP_UNIT = {"C": TEMP_CELSIUS, "F": TEMP_FAHRENHEIT}
SUPPORT_PRESET = [PRESET_NONE, PRESET_BOOST]
PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(seconds=15)
_LOGGER = logging.getLogger()
@ -105,6 +102,7 @@ class HiveClimateEntity(HiveEntity, ClimateEntity):
"""Hive Climate Device."""
_attr_hvac_modes = [HVACMode.AUTO, HVACMode.HEAT, HVACMode.OFF]
_attr_preset_modes = [PRESET_BOOST, PRESET_NONE]
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
)
@ -113,84 +111,7 @@ class HiveClimateEntity(HiveEntity, ClimateEntity):
"""Initialize the Climate device."""
super().__init__(hive_session, hive_device)
self.thermostat_node_id = hive_device["device_id"]
self.temperature_type = TEMP_UNIT.get(hive_device["temperatureunit"])
@property
def unique_id(self):
"""Return unique ID of entity."""
return self._unique_id
@property
def device_info(self) -> DeviceInfo:
"""Return device information."""
return DeviceInfo(
identifiers={(DOMAIN, self.device["device_id"])},
manufacturer=self.device["deviceData"]["manufacturer"],
model=self.device["deviceData"]["model"],
name=self.device["device_name"],
sw_version=self.device["deviceData"]["version"],
via_device=(DOMAIN, self.device["parentDevice"]),
)
@property
def name(self):
"""Return the name of the Climate device."""
return self.device["haName"]
@property
def available(self):
"""Return if the device is available."""
return self.device["deviceData"]["online"]
@property
def hvac_mode(self) -> HVACMode:
"""Return hvac operation ie. heat, cool mode.
Need to be one of HVAC_MODE_*.
"""
return HIVE_TO_HASS_STATE[self.device["status"]["mode"]]
@property
def hvac_action(self) -> HVACAction:
"""Return current HVAC action."""
return HIVE_TO_HASS_HVAC_ACTION[self.device["status"]["action"]]
@property
def temperature_unit(self):
"""Return the unit of measurement."""
return self.temperature_type
@property
def current_temperature(self):
"""Return the current temperature."""
return self.device["status"]["current_temperature"]
@property
def target_temperature(self):
"""Return the target temperature."""
return self.device["status"]["target_temperature"]
@property
def min_temp(self):
"""Return minimum temperature."""
return self.device["min_temp"]
@property
def max_temp(self):
"""Return the maximum temperature."""
return self.device["max_temp"]
@property
def preset_mode(self):
"""Return the current preset mode, e.g., home, away, temp."""
if self.device["status"]["boost"] == "ON":
return PRESET_BOOST
return PRESET_NONE
@property
def preset_modes(self):
"""Return a list of available preset modes."""
return SUPPORT_PRESET
self._attr_temperature_unit = TEMP_UNIT.get(hive_device["temperatureunit"])
@refresh_system
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
@ -236,3 +157,19 @@ class HiveClimateEntity(HiveEntity, ClimateEntity):
"""Update all Node data from Hive."""
await self.hive.session.updateData(self.device)
self.device = await self.hive.heating.getClimate(self.device)
self._attr_available = self.device["deviceData"].get("online")
if self._attr_available:
self._attr_hvac_mode = HIVE_TO_HASS_STATE[self.device["status"]["mode"]]
self._attr_hvac_action = HIVE_TO_HASS_HVAC_ACTION[
self.device["status"]["action"]
]
self._attr_current_temperature = self.device["status"][
"current_temperature"
]
self._attr_target_temperature = self.device["status"]["target_temperature"]
self._attr_min_temp = self.device["min_temp"]
self._attr_max_temp = self.device["max_temp"]
if self.device["status"]["boost"] == "ON":
self._attr_preset_mode = PRESET_BOOST
else:
self._attr_preset_mode = PRESET_NONE