1 """Support for interface with a Gree climate systems."""
3 from __future__
import annotations
8 from greeclimate.device
import (
47 DISPATCH_DEVICE_DISCOVERED,
51 TARGET_TEMPERATURE_STEP,
53 from .coordinator
import DeviceDataUpdateCoordinator
54 from .entity
import GreeEntity
56 _LOGGER = logging.getLogger(__name__)
59 Mode.Auto: HVACMode.AUTO,
60 Mode.Cool: HVACMode.COOL,
61 Mode.Dry: HVACMode.DRY,
62 Mode.Fan: HVACMode.FAN_ONLY,
63 Mode.Heat: HVACMode.HEAT,
65 HVAC_MODES_REVERSE = {v: k
for k, v
in HVAC_MODES.items()}
76 FanSpeed.Auto: FAN_AUTO,
77 FanSpeed.Low: FAN_LOW,
78 FanSpeed.MediumLow: FAN_MEDIUM_LOW,
79 FanSpeed.Medium: FAN_MEDIUM,
80 FanSpeed.MediumHigh: FAN_MEDIUM_HIGH,
81 FanSpeed.High: FAN_HIGH,
83 FAN_MODES_REVERSE = {v: k
for k, v
in FAN_MODES.items()}
85 SWING_MODES = [SWING_OFF, SWING_VERTICAL, SWING_HORIZONTAL, SWING_BOTH]
91 async_add_entities: AddEntitiesCallback,
93 """Set up the Gree HVAC device from a config entry."""
96 def init_device(coordinator):
97 """Register the device."""
100 for coordinator
in hass.data[DOMAIN][COORDINATORS]:
101 init_device(coordinator)
103 entry.async_on_unload(
109 """Representation of a Gree HVAC device."""
111 _attr_precision = PRECISION_WHOLE
112 _attr_supported_features = (
113 ClimateEntityFeature.TARGET_TEMPERATURE
114 | ClimateEntityFeature.FAN_MODE
115 | ClimateEntityFeature.PRESET_MODE
116 | ClimateEntityFeature.SWING_MODE
117 | ClimateEntityFeature.TURN_OFF
118 | ClimateEntityFeature.TURN_ON
120 _attr_target_temperature_step = TARGET_TEMPERATURE_STEP
121 _attr_hvac_modes = [*HVAC_MODES_REVERSE, HVACMode.OFF]
122 _attr_preset_modes = PRESET_MODES
123 _attr_fan_modes = [*FAN_MODES_REVERSE]
124 _attr_swing_modes = SWING_MODES
126 _attr_temperature_unit = UnitOfTemperature.CELSIUS
127 _attr_min_temp = TEMP_MIN
128 _attr_max_temp = TEMP_MAX
129 _enable_turn_on_off_backwards_compatibility =
False
131 def __init__(self, coordinator: DeviceDataUpdateCoordinator) ->
None:
132 """Initialize the Gree device."""
138 """Return the reported current temperature for the device."""
139 return self.coordinator.device.current_temperature
143 """Return the target temperature for the device."""
144 return self.coordinator.device.target_temperature
147 """Set new target temperature."""
148 if ATTR_TEMPERATURE
not in kwargs:
149 raise ValueError(f
"Missing parameter {ATTR_TEMPERATURE}")
151 if hvac_mode := kwargs.get(ATTR_HVAC_MODE):
154 temperature = kwargs[ATTR_TEMPERATURE]
156 "Setting temperature to %d for %s",
161 self.coordinator.device.target_temperature = temperature
167 """Return the current HVAC mode for the device."""
168 if not self.coordinator.device.power:
171 return HVAC_MODES.get(self.coordinator.device.mode)
174 """Set new target hvac mode."""
175 if hvac_mode
not in self.
hvac_modeshvac_modes:
176 raise ValueError(f
"Invalid hvac_mode: {hvac_mode}")
179 "Setting HVAC mode to %s for device %s",
184 if hvac_mode == HVACMode.OFF:
185 self.coordinator.device.power =
False
190 if not self.coordinator.device.power:
191 self.coordinator.device.power =
True
193 self.coordinator.device.mode = HVAC_MODES_REVERSE.get(hvac_mode)
198 """Turn on the device."""
199 _LOGGER.debug(
"Turning on HVAC for device %s", self.
_attr_name_attr_name)
201 self.coordinator.device.power =
True
206 """Turn off the device."""
207 _LOGGER.debug(
"Turning off HVAC for device %s", self.
_attr_name_attr_name)
209 self.coordinator.device.power =
False
215 """Return the current preset mode for the device."""
216 if self.coordinator.device.steady_heat:
218 if self.coordinator.device.power_save:
220 if self.coordinator.device.sleep:
222 if self.coordinator.device.turbo:
227 """Set new preset mode."""
228 if preset_mode
not in PRESET_MODES:
229 raise ValueError(f
"Invalid preset mode: {preset_mode}")
232 "Setting preset mode to %s for device %s",
237 self.coordinator.device.steady_heat =
False
238 self.coordinator.device.power_save =
False
239 self.coordinator.device.turbo =
False
240 self.coordinator.device.sleep =
False
242 if preset_mode == PRESET_AWAY:
243 self.coordinator.device.steady_heat =
True
244 elif preset_mode == PRESET_ECO:
245 self.coordinator.device.power_save =
True
246 elif preset_mode == PRESET_BOOST:
247 self.coordinator.device.turbo =
True
248 elif preset_mode == PRESET_SLEEP:
249 self.coordinator.device.sleep =
True
256 """Return the current fan mode for the device."""
257 speed = self.coordinator.device.fan_speed
258 return FAN_MODES.get(speed)
261 """Set new target fan mode."""
262 if fan_mode
not in FAN_MODES_REVERSE:
263 raise ValueError(f
"Invalid fan mode: {fan_mode}")
265 self.coordinator.device.fan_speed = FAN_MODES_REVERSE.get(fan_mode)
271 """Return the current swing mode for the device."""
272 h_swing = self.coordinator.device.horizontal_swing == HorizontalSwing.FullSwing
273 v_swing = self.coordinator.device.vertical_swing == VerticalSwing.FullSwing
275 if h_swing
and v_swing:
278 return SWING_HORIZONTAL
280 return SWING_VERTICAL
284 """Set new target swing operation."""
285 if swing_mode
not in SWING_MODES:
286 raise ValueError(f
"Invalid swing mode: {swing_mode}")
289 "Setting swing mode to %s for device %s",
294 self.coordinator.device.horizontal_swing = HorizontalSwing.Center
295 self.coordinator.device.vertical_swing = VerticalSwing.FixedMiddle
296 if swing_mode
in (SWING_BOTH, SWING_HORIZONTAL):
297 self.coordinator.device.horizontal_swing = HorizontalSwing.FullSwing
298 if swing_mode
in (SWING_BOTH, SWING_VERTICAL):
299 self.coordinator.device.vertical_swing = VerticalSwing.FullSwing
305 """Update the state of the entity."""
306 units = self.coordinator.device.temperature_units
308 units == TemperatureUnits.C
311 _LOGGER.debug(
"Setting temperature unit to Celsius")
316 units == TemperatureUnits.F
319 _LOGGER.debug(
"Setting temperature unit to Fahrenheit")
None async_set_hvac_mode(self, HVACMode hvac_mode)
list[HVACMode] hvac_modes(self)
None async_turn_off(self)
None __init__(self, DeviceDataUpdateCoordinator coordinator)
None async_set_swing_mode(self, str swing_mode)
float target_temperature(self)
None async_set_temperature(self, **Any kwargs)
None async_set_fan_mode(self, str fan_mode)
None _handle_coordinator_update(self)
float current_temperature(self)
None async_set_hvac_mode(self, HVACMode hvac_mode)
None async_set_preset_mode(self, str preset_mode)
def push_state_update(self)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)