1 """Support for interface with a Gree climate systems."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
9 from greeclimate.device
import Device
14 SwitchEntityDescription,
21 from .const
import COORDINATORS, DISPATCH_DEVICE_DISCOVERED, DOMAIN
22 from .entity
import GreeEntity
25 @dataclass(kw_only=True, frozen=True)
27 """Describes a Gree switch entity."""
29 get_value_fn: Callable[[Device], bool]
30 set_value_fn: Callable[[Device, bool],
None]
34 """Typed helper to set device light property."""
39 """Typed helper to set device quiet property."""
44 """Typed helper to set device fresh_air property."""
45 device.fresh_air = value
49 """Typed helper to set device xfan property."""
54 """Typed helper to set device anion property."""
58 GREE_SWITCHES: tuple[GreeSwitchEntityDescription, ...] = (
61 translation_key=
"light",
62 get_value_fn=
lambda d: d.light,
63 set_value_fn=_set_light,
67 translation_key=
"quiet",
68 get_value_fn=
lambda d: d.quiet,
69 set_value_fn=_set_quiet,
73 translation_key=
"fresh_air",
74 get_value_fn=
lambda d: d.fresh_air,
75 set_value_fn=_set_fresh_air,
79 translation_key=
"xfan",
80 get_value_fn=
lambda d: d.xfan,
81 set_value_fn=_set_xfan,
85 translation_key=
"health_mode",
86 get_value_fn=
lambda d: d.anion,
87 set_value_fn=_set_anion,
88 entity_registry_enabled_default=
False,
96 async_add_entities: AddEntitiesCallback,
98 """Set up the Gree HVAC device from a config entry."""
101 def init_device(coordinator):
102 """Register the device."""
105 GreeSwitch(coordinator=coordinator, description=description)
106 for description
in GREE_SWITCHES
109 for coordinator
in hass.data[DOMAIN][COORDINATORS]:
110 init_device(coordinator)
112 entry.async_on_unload(
118 """Generic Gree switch entity."""
120 _attr_device_class = SwitchDeviceClass.SWITCH
121 entity_description: GreeSwitchEntityDescription
123 def __init__(self, coordinator, description: GreeSwitchEntityDescription) ->
None:
124 """Initialize the Gree device."""
127 super().
__init__(coordinator, description.key)
131 """Return if the state is turned on."""
132 return self.
entity_descriptionentity_description.get_value_fn(self.coordinator.device)
135 """Turn the entity on."""
141 """Turn the entity off."""
142 self.
entity_descriptionentity_description.set_value_fn(self.coordinator.device,
False)
def push_state_update(self)
None __init__(self, coordinator, GreeSwitchEntityDescription description)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_write_ha_state(self)
None _set_light(Device device, bool value)
None _set_xfan(Device device, bool value)
None _set_anion(Device device, bool value)
None _set_quiet(Device device, bool value)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
None _set_fresh_air(Device device, bool value)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)