diff --git a/custom_components/hive_mqtt_orchestrator/climate.py b/custom_components/hive_mqtt_orchestrator/climate.py index 73751da..77ad9e4 100644 --- a/custom_components/hive_mqtt_orchestrator/climate.py +++ b/custom_components/hive_mqtt_orchestrator/climate.py @@ -59,6 +59,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback ): """Set up the sensor platform.""" + _entities = {} hive_climate_entity_description = HiveClimateEntityDescription( @@ -74,7 +75,7 @@ async def async_setup_entry( _entities = [HiveClimateEntity(entity_description=hive_climate_entity_description) ] async_add_entities( - [climateEntity for climateEntity in _entities], + climateEntity for climateEntity in _entities ) hass.data[DOMAIN][config_entry.entry_id][Platform.CLIMATE] = _entities @@ -82,7 +83,6 @@ async def async_setup_entry( class HiveClimateEntity(HiveEntity, ClimateEntity): """hive_mqtt_orchestrator Climate class.""" - def __init__( self, entity_description: HiveClimateEntityDescription, @@ -120,6 +120,8 @@ def __init__( @property def hvac_mode(self): + """Get the current hvac mode.""" + if not self._mqtt_data: return @@ -133,6 +135,8 @@ def hvac_mode(self): return HVACMode.OFF async def async_set_hvac_mode(self, hvac_mode): + """Set the hvac mode.""" + if hvac_mode in self._attr_hvac_modes: self._attr_hvac_mode = hvac_mode else: @@ -171,6 +175,8 @@ async def async_set_hvac_mode(self, hvac_mode): @property def hvac_action(self): + """Get the current action.""" + if not self._mqtt_data: return @@ -185,6 +191,8 @@ def hvac_action(self): @property def current_temperature(self): + """Get the current temperature.""" + if not self._mqtt_data: return if "local_temperature_heat" in self._mqtt_data: @@ -192,6 +200,8 @@ def current_temperature(self): @property def target_temperature(self): + """Get the target temperature.""" + if not self._mqtt_data: return if "occupied_heating_setpoint_heat" in self._mqtt_data: @@ -200,22 +210,30 @@ def target_temperature(self): return self._mqtt_data["occupied_heating_setpoint_heat"] async def async_set_temperature(self, temperature, **kwargs): + """Set the target temperature.""" + payload = r'{"occupied_heating_setpoint_heat":' + str(temperature) + r'}' LOGGER.debug("Sending to {self._topic}/set message {payload}") await mqtt_client.async_publish(self.hass, self._topic + "/set", payload) def _climate_preset(self, mode): + """Get the current preset.""" + return next((k for k, v in PRESET_MAP.items() if v == mode), PRESET_MAP[PRESET_NONE]) @property def preset_mode(self): + """Get the preset mode.""" + if not self._mqtt_data: return if "system_mode_heat" in self._mqtt_data: return self._climate_preset(self._mqtt_data["system_mode_heat"]) async def async_set_preset_mode(self, preset_mode): + """Set the preset mode.""" + if preset_mode == "boost": self._pre_boost_hvac_mode = self.hvac_mode self._pre_boost_occupied_heating_setpoint_heat = self.target_temperature @@ -231,6 +249,7 @@ async def async_set_preset_mode(self, preset_mode): def process_update(self, mqtt_data) -> None: """Update the state of the sensor.""" + self._mqtt_data = mqtt_data if (self.hass is not None): # this is a hack to get around the fact that the entity is not yet initialized at first self.async_schedule_update_ha_state() diff --git a/custom_components/hive_mqtt_orchestrator/number.py b/custom_components/hive_mqtt_orchestrator/number.py index f779843..0109fd3 100644 --- a/custom_components/hive_mqtt_orchestrator/number.py +++ b/custom_components/hive_mqtt_orchestrator/number.py @@ -143,7 +143,7 @@ async def async_setup_entry( _entities = [HiveNumber(entity_description=entity_description,) for entity_description in entity_descriptions] async_add_entities( - [sensorEntity for sensorEntity in _entities], + sensorEntity for sensorEntity in _entities ) hass.data[DOMAIN][config_entry.entry_id][Platform.NUMBER] = _entities diff --git a/custom_components/hive_mqtt_orchestrator/select.py b/custom_components/hive_mqtt_orchestrator/select.py index 7c40a80..ee8b87d 100644 --- a/custom_components/hive_mqtt_orchestrator/select.py +++ b/custom_components/hive_mqtt_orchestrator/select.py @@ -63,7 +63,7 @@ async def async_setup_entry( _entities = [HiveSelect(entity_description=entity_description,) for entity_description in ENTITY_DESCRIPTIONS] async_add_entities( - [sensorEntity for sensorEntity in _entities], + sensorEntity for sensorEntity in _entities ) hass.data[DOMAIN][config_entry.entry_id][Platform.SELECT] = _entities diff --git a/custom_components/hive_mqtt_orchestrator/sensor.py b/custom_components/hive_mqtt_orchestrator/sensor.py index 86516e6..e69e940 100644 --- a/custom_components/hive_mqtt_orchestrator/sensor.py +++ b/custom_components/hive_mqtt_orchestrator/sensor.py @@ -78,7 +78,7 @@ async def async_setup_entry( _entities = [HiveSensor(entity_description=entity_description,) for entity_description in entity_descriptions] async_add_entities( - [sensorEntity for sensorEntity in _entities], + sensorEntity for sensorEntity in _entities ) hass.data[DOMAIN][config_entry.entry_id][Platform.SENSOR] = _entities diff --git a/custom_components/hive_mqtt_orchestrator/switch.py b/custom_components/hive_mqtt_orchestrator/switch.py index 744f99b..088fc7d 100644 --- a/custom_components/hive_mqtt_orchestrator/switch.py +++ b/custom_components/hive_mqtt_orchestrator/switch.py @@ -75,7 +75,7 @@ async def async_setup_entry( _entities = [HiveSwitch(entity_description=entity_description,) for entity_description in entity_descriptions] async_add_entities( - [sensorEntity for sensorEntity in _entities], + sensorEntity for sensorEntity in _entities ) hass.data[DOMAIN][config_entry.entry_id][Platform.SWITCH] = _entities