1 """Pyaehw4a1 platform to control of Hisense AEH-W4A1 Climate Devices."""
3 from __future__
import annotations
8 from pyaehw4a1.aehw4a1
import AehW4a1
9 import pyaehw4a1.exceptions
33 from .
import CONF_IP_ADDRESS, DOMAIN
75 "0001": HVACMode.HEAT,
76 "0010": HVACMode.COOL,
78 "0000": HVACMode.FAN_ONLY,
83 HVACMode.HEAT:
"mode_heat",
84 HVACMode.COOL:
"mode_cool",
85 HVACMode.DRY:
"mode_dry",
86 HVACMode.FAN_ONLY:
"mode_fan",
89 AC_TO_HA_FAN_MODES = {
94 "00000110": FAN_MEDIUM,
98 HA_FAN_MODES_TO_AC = {
100 FAN_LOW:
"speed_low",
101 FAN_MEDIUM:
"speed_med",
102 FAN_HIGH:
"speed_max",
103 FAN_AUTO:
"speed_auto",
108 "10": SWING_VERTICAL,
109 "01": SWING_HORIZONTAL,
113 _LOGGER = logging.getLogger(__name__)
117 _LOGGER.debug(
"Found device at %s", device)
123 config_entry: ConfigEntry,
124 async_add_entities: AddEntitiesCallback,
126 """Set up the AEH-W4A1 climate platform."""
128 if hass.data[DOMAIN].
get(CONF_IP_ADDRESS):
129 devices = hass.data[DOMAIN][CONF_IP_ADDRESS]
132 devices = await AehW4a1().discovery()
139 """Representation of a Hisense AEH-W4A1 module for climate device."""
141 _attr_hvac_modes = HVAC_MODES
142 _attr_precision = PRECISION_WHOLE
143 _attr_supported_features = (
144 ClimateEntityFeature.TARGET_TEMPERATURE
145 | ClimateEntityFeature.FAN_MODE
146 | ClimateEntityFeature.SWING_MODE
147 | ClimateEntityFeature.PRESET_MODE
148 | ClimateEntityFeature.TURN_OFF
149 | ClimateEntityFeature.TURN_ON
151 _attr_fan_modes = FAN_MODES
152 _attr_swing_modes = SWING_MODES
153 _attr_preset_modes = PRESET_MODES
154 _attr_available =
False
155 _attr_target_temperature_step = 1
156 _previous_state: HVACMode | str |
None =
None
157 _on: str |
None =
None
158 _enable_turn_on_off_backwards_compatibility =
False
161 """Initialize the climate device."""
167 """Pull state from AEH-W4A1."""
169 status = await self.
_device_device.command(
"status_102_0")
170 except pyaehw4a1.exceptions.ConnectionError
as library_error:
172 "Unexpected error of %s: %s", self.
_attr_unique_id_attr_unique_id, library_error
179 self.
_on_on = status[
"run_status"]
181 if status[
"temperature_Fahrenheit"] ==
"0":
192 if self.
_on_on ==
"1":
193 device_mode = status[
"mode_status"]
196 fan_mode = status[
"wind_status"]
199 swing_mode = f
'{status["up_down"]}{status["left_right"]}'
202 if self.
_attr_hvac_mode_attr_hvac_mode
in (HVACMode.COOL, HVACMode.HEAT):
204 status[
"indoor_temperature_setting"], 2
209 if status[
"efficient"] ==
"1":
211 elif status[
"low_electricity"] ==
"1":
213 elif status[
"sleep_status"] ==
"0000001":
215 elif status[
"sleep_status"] ==
"0000010":
217 elif status[
"sleep_status"] ==
"0000011":
219 elif status[
"sleep_status"] ==
"0000100":
231 """Set new target temperatures."""
232 if self.
_on_on !=
"1":
234 "AC at %s is off, could not set temperature", self.
_attr_unique_id_attr_unique_id
237 if (temp := kwargs.get(ATTR_TEMPERATURE))
is not None:
238 _LOGGER.debug(
"Setting temp of %s to %s", self.
_attr_unique_id_attr_unique_id, temp)
242 await self.
_device_device.command(f
"temp_{int(temp)}_C")
244 await self.
_device_device.command(f
"temp_{int(temp)}_F")
247 """Set new fan mode."""
248 if self.
_on_on !=
"1":
250 "AC at %s is off, could not set fan mode", self.
_attr_unique_id_attr_unique_id
253 if self.
_attr_hvac_mode_attr_hvac_mode
in (HVACMode.COOL, HVACMode.FAN_ONLY)
and (
254 self.
_attr_hvac_mode_attr_hvac_mode != HVACMode.FAN_ONLY
or fan_mode != FAN_AUTO
257 "Setting fan mode of %s to %s", self.
_attr_unique_id_attr_unique_id, fan_mode
259 await self.
_device_device.command(HA_FAN_MODES_TO_AC[fan_mode])
262 """Set new target swing operation."""
263 if self.
_on_on !=
"1":
265 "AC at %s is off, could not set swing mode", self.
_attr_unique_id_attr_unique_id
270 "Setting swing mode of %s to %s", self.
_attr_unique_id_attr_unique_id, swing_mode
274 if swing_mode == SWING_OFF
and swing_act != SWING_OFF:
275 if swing_act
in (SWING_HORIZONTAL, SWING_BOTH):
276 await self.
_device_device.command(
"hor_dir")
277 if swing_act
in (SWING_VERTICAL, SWING_BOTH):
278 await self.
_device_device.command(
"vert_dir")
280 if swing_mode == SWING_BOTH
and swing_act != SWING_BOTH:
281 if swing_act
in (SWING_OFF, SWING_HORIZONTAL):
282 await self.
_device_device.command(
"vert_swing")
283 if swing_act
in (SWING_OFF, SWING_VERTICAL):
284 await self.
_device_device.command(
"hor_swing")
286 if swing_mode == SWING_VERTICAL
and swing_act != SWING_VERTICAL:
287 if swing_act
in (SWING_OFF, SWING_HORIZONTAL):
288 await self.
_device_device.command(
"vert_swing")
289 if swing_act
in (SWING_BOTH, SWING_HORIZONTAL):
290 await self.
_device_device.command(
"hor_dir")
292 if swing_mode == SWING_HORIZONTAL
and swing_act != SWING_HORIZONTAL:
293 if swing_act
in (SWING_BOTH, SWING_VERTICAL):
294 await self.
_device_device.command(
"vert_dir")
295 if swing_act
in (SWING_OFF, SWING_VERTICAL):
296 await self.
_device_device.command(
"hor_swing")
299 """Set new preset mode."""
300 if self.
_on_on !=
"1":
301 if preset_mode == PRESET_NONE:
306 "Setting preset mode of %s to %s", self.
_attr_unique_id_attr_unique_id, preset_mode
309 if preset_mode == PRESET_ECO:
310 await self.
_device_device.command(
"energysave_on")
312 elif preset_mode == PRESET_BOOST:
313 await self.
_device_device.command(
"turbo_on")
315 elif preset_mode == PRESET_SLEEP:
316 await self.
_device_device.command(
"sleep_1")
318 elif preset_mode ==
"sleep_2":
319 await self.
_device_device.command(
"sleep_2")
321 elif preset_mode ==
"sleep_3":
322 await self.
_device_device.command(
"sleep_3")
324 elif preset_mode ==
"sleep_4":
325 await self.
_device_device.command(
"sleep_4")
329 await self.
_device_device.command(
"energysave_off")
331 await self.
_device_device.command(
"turbo_off")
332 elif self.
_previous_state_previous_state
in HA_STATE_TO_AC
and isinstance(
339 """Set new operation mode."""
341 "Setting operation mode of %s to %s", self.
_attr_unique_id_attr_unique_id, hvac_mode
343 if hvac_mode == HVACMode.OFF:
346 await self.
_device_device.command(HA_STATE_TO_AC[hvac_mode])
347 if self.
_on_on !=
"1":
353 await self.
_device_device.command(
"on")
358 await self.
_device_device.command(
"off")
None async_set_preset_mode(self, str preset_mode)
None async_turn_off(self)
None async_turn_off(self)
None async_set_fan_mode(self, str fan_mode)
None async_set_swing_mode(self, str swing_mode)
_attr_current_temperature
None async_set_hvac_mode(self, HVACMode hvac_mode)
None async_set_preset_mode(self, str preset_mode)
def __init__(self, device)
None async_set_temperature(self, **Any kwargs)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
def _build_entity(device)