|
1 | 1 | from __future__ import annotations
|
2 | 2 | import logging
|
3 | 3 |
|
| 4 | +from typing import Any |
| 5 | + |
4 | 6 | from homeassistant.config_entries import ConfigEntry
|
5 | 7 | from homeassistant.core import HomeAssistant, callback
|
6 | 8 | from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
16 | 18 | STATE_PERFORMANCE,
|
17 | 19 | )
|
18 | 20 |
|
19 |
| -from .definitions import lookup_by_value, OperatingMode |
| 21 | +from .definitions import OperatingMode |
20 | 22 | from . import build_device_info
|
21 | 23 | from .const import DeviceType
|
22 | 24 |
|
@@ -164,6 +166,39 @@ def heat_delta_received(message):
|
164 | 166 | 1,
|
165 | 167 | )
|
166 | 168 |
|
| 169 | + @callback |
| 170 | + def operating_mode_received(message): |
| 171 | + self._operating_mode = OperatingMode.from_mqtt(message.payload) |
| 172 | + self.async_write_ha_state() |
| 173 | + |
| 174 | + await mqtt.async_subscribe( |
| 175 | + self.hass, |
| 176 | + f"{self.discovery_prefix}main/Operating_Mode_State", |
| 177 | + operating_mode_received, |
| 178 | + 1, |
| 179 | + ) |
| 180 | + |
| 181 | + async def async_turn_on(self, **kwargs: Any) -> None: |
| 182 | + new_operating_mode = self._operating_mode | OperatingMode.DHW |
| 183 | + await async_publish( |
| 184 | + self.hass, |
| 185 | + f"{self.discovery_prefix}commands/SetOperationMode", |
| 186 | + new_operating_mode.to_mqtt(), |
| 187 | + 0, |
| 188 | + False, |
| 189 | + "utf-8", |
| 190 | + ) |
| 191 | + async def async_turn_off(self, **kwargs: Any) -> None: |
| 192 | + new_operating_mode = self._operating_mode & ~OperatingMode.DHW |
| 193 | + await async_publish( |
| 194 | + self.hass, |
| 195 | + f"{self.discovery_prefix}commands/SetOperationMode", |
| 196 | + new_operating_mode.to_mqtt(), |
| 197 | + 0, |
| 198 | + False, |
| 199 | + "utf-8", |
| 200 | + ) |
| 201 | + |
167 | 202 | @property
|
168 | 203 | def device_info(self):
|
169 | 204 | return build_device_info(DeviceType.HEATPUMP, self.discovery_prefix)
|
0 commit comments