diff --git a/custom_components/ithodaalderop/fans/base_fans.py b/custom_components/ithodaalderop/fans/base_fans.py index 39861fc..93c1120 100644 --- a/custom_components/ithodaalderop/fans/base_fans.py +++ b/custom_components/ithodaalderop/fans/base_fans.py @@ -22,32 +22,17 @@ def __init__( ) -> None: """Initialize the fan.""" self.entity_description = description - self._preset_mode = None - self.entity_description.translation_key = self.entity_description.key + self._attr_preset_modes = self.entity_description.preset_modes self._attr_device_info = DeviceInfo( identifiers={(DOMAIN, get_entity_prefix(config_entry.data))}, manufacturer=MANUFACTURER, model=get_device_model(config_entry.data), name=get_device_name(config_entry.data), ) + self._attr_unique_id = ( f"{get_entity_prefix(config_entry.data)}_{description.key}".lower() ) self.entity_id = f"fan.{self._attr_unique_id}" - - @property - def preset_modes(self): - """Return the available preset modes.""" - return self.entity_description.preset_modes - - @property - def supported_features(self) -> FanEntityFeature: - """Return the list of supported features.""" - return self.entity_description.supported_features - - @property - def preset_mode(self): - """Return the current preset mode.""" - return self._preset_mode diff --git a/custom_components/ithodaalderop/fans/cve_hru200.py b/custom_components/ithodaalderop/fans/cve_hru200.py index 0719f2c..889b294 100644 --- a/custom_components/ithodaalderop/fans/cve_hru200.py +++ b/custom_components/ithodaalderop/fans/cve_hru200.py @@ -43,8 +43,6 @@ def get_cve_hru200_fan(config_entry: ConfigEntry): class IthoFanCVE_HRU200(IthoBaseFan): """Representation of an MQTT-controlled fan.""" - _is_on = None - async def async_added_to_hass(self) -> None: """Subscribe to MQTT events.""" await mqtt.async_subscribe( @@ -56,20 +54,22 @@ def _message_received(self, msg): """Handle preset mode update via MQTT.""" try: data = json.loads(msg.payload) - speed = int(data.get("Ventilation level (%)", -1)) + int( + percentage = int(data.get("Ventilation level (%)", -1)) + int( data.get("Ventilation setpoint (%)", -1) ) - - self._is_on = speed > 0 + self._attr_percentage = percentage except ValueError: - self._is_on = None + self._attr_percentage = None + + self.async_write_ha_state() async def async_set_preset_mode(self, preset_mode): """Set the fan preset mode.""" if preset_mode in PRESET_MODES: preset_command = PRESET_MODES[preset_mode] - payload = json.dumps({self.entity_description.command_key: preset_command}) + # payload = json.dumps({self.entity_description.command_key: preset_command}) + payload = json.dumps(preset_command) await mqtt.async_publish( self.hass, self.entity_description.command_topic, @@ -80,13 +80,14 @@ async def async_set_preset_mode(self, preset_mode): async def async_set_percentage(self, percentage: int) -> None: """Set the speed of the fan, as a percentage.""" - payload = json.dumps({self.entity_description.command_key: percentage * 2.55}) + # payload = json.dumps({self.entity_description.command_key: percentage * 2.55}) + payload = json.dumps(int(percentage * 2.55)) await mqtt.async_publish( self.hass, self.entity_description.command_topic, payload, ) - self.percentage = percentage + self._attr_percentage = percentage self.async_write_ha_state() async def async_turn_on(self, *args, **kwargs): @@ -96,8 +97,3 @@ async def async_turn_on(self, *args, **kwargs): async def async_turn_off(self, **kwargs): """Turn off the fan.""" await self.async_set_percentage(0) - - @property - def is_on(self): - """Return true if the fan is on.""" - return self._is_on diff --git a/custom_components/ithodaalderop/fans/hru350.py b/custom_components/ithodaalderop/fans/hru350.py index 05bf68b..479189e 100644 --- a/custom_components/ithodaalderop/fans/hru350.py +++ b/custom_components/ithodaalderop/fans/hru350.py @@ -67,8 +67,7 @@ def _message_received(self, msg): data = json.loads(msg.payload) actual_mode = int(data.get("Actual Mode", -1)) - self._preset_mode = ACTUAL_MODES.get(actual_mode) - + self._attr_preset_mode = ACTUAL_MODES.get(actual_mode) self.async_write_ha_state() except ValueError: _LOGGER.error("Invalid JSON received for preset mode: %s", msg.payload) @@ -84,7 +83,7 @@ async def async_set_preset_mode(self, preset_mode): self.entity_description.command_topic, payload, ) - self._preset_mode = preset_mode + self._attr_preset_mode = preset_mode self.async_write_ha_state() else: _LOGGER.warning(f"Invalid preset mode: {preset_mode}") diff --git a/custom_components/ithodaalderop/manifest.json b/custom_components/ithodaalderop/manifest.json index ff687e0..d5759e9 100644 --- a/custom_components/ithodaalderop/manifest.json +++ b/custom_components/ithodaalderop/manifest.json @@ -14,5 +14,5 @@ "mqtt": ["ithohru/#"], "requirements": [ ], - "version": "2.5.0-b7" + "version": "2.5.0-b8" }