1 """Support for the Daikin HVAC."""
3 from __future__
import annotations
27 from .
import DOMAIN
as DAIKIN_DOMAIN
29 ATTR_INSIDE_TEMPERATURE,
30 ATTR_OUTSIDE_TEMPERATURE,
33 ATTR_TARGET_TEMPERATURE,
35 from .coordinator
import DaikinCoordinator
36 from .entity
import DaikinEntity
38 _LOGGER = logging.getLogger(__name__)
41 HA_STATE_TO_DAIKIN = {
42 HVACMode.FAN_ONLY:
"fan",
44 HVACMode.COOL:
"cool",
46 HVACMode.HEAT_COOL:
"auto",
50 DAIKIN_TO_HA_STATE = {
51 "fan": HVACMode.FAN_ONLY,
53 "cool": HVACMode.COOL,
55 "auto": HVACMode.HEAT_COOL,
59 HA_STATE_TO_CURRENT_HVAC = {
60 HVACMode.COOL: HVACAction.COOLING,
61 HVACMode.HEAT: HVACAction.HEATING,
62 HVACMode.OFF: HVACAction.OFF,
65 HA_PRESET_TO_DAIKIN = {
68 PRESET_BOOST:
"powerful",
73 ATTR_PRESET_MODE:
"en_hol",
74 ATTR_HVAC_MODE:
"mode",
75 ATTR_FAN_MODE:
"f_rate",
76 ATTR_SWING_MODE:
"f_dir",
77 ATTR_INSIDE_TEMPERATURE:
"htemp",
78 ATTR_OUTSIDE_TEMPERATURE:
"otemp",
79 ATTR_TARGET_TEMPERATURE:
"stemp",
82 DAIKIN_ATTR_ADVANCED =
"adv"
86 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
88 """Set up Daikin climate based on config_entry."""
89 daikin_api = hass.data[DAIKIN_DOMAIN].
get(entry.entry_id)
94 """Format target temperature to be sent to the Daikin unit, rounding to nearest half degree."""
95 return str(round(
float(target_temperature) * 2, 0) / 2).rstrip(
"0").rstrip(
".")
99 """Representation of a Daikin HVAC."""
102 _attr_temperature_unit = UnitOfTemperature.CELSIUS
103 _attr_hvac_modes =
list(HA_STATE_TO_DAIKIN)
104 _attr_target_temperature_step = 1
105 _attr_fan_modes: list[str]
106 _attr_swing_modes: list[str]
107 _enable_turn_on_off_backwards_compatibility =
False
109 def __init__(self, coordinator: DaikinCoordinator) ->
None:
110 """Initialize the climate device."""
114 self._list: dict[str, list[Any]] = {
121 ClimateEntityFeature.TURN_ON
122 | ClimateEntityFeature.TURN_OFF
123 | ClimateEntityFeature.TARGET_TEMPERATURE
135 async
def _set(self, settings: dict[str, Any]) ->
None:
136 """Set device settings using API."""
137 values: dict[str, Any] = {}
139 for attr
in (ATTR_TEMPERATURE, ATTR_FAN_MODE, ATTR_SWING_MODE, ATTR_HVAC_MODE):
140 if (value := settings.get(attr))
is None:
143 if (daikin_attr := HA_ATTR_TO_DAIKIN.get(attr))
is not None:
144 if attr == ATTR_HVAC_MODE:
145 values[daikin_attr] = HA_STATE_TO_DAIKIN[value]
146 elif value
in self._list[attr]:
147 values[daikin_attr] = value.lower()
149 _LOGGER.error(
"Invalid value %s for %s", attr, value)
152 elif attr == ATTR_TEMPERATURE:
154 values[HA_ATTR_TO_DAIKIN[ATTR_TARGET_TEMPERATURE]] = (
158 _LOGGER.error(
"Invalid temperature %s", value)
166 """Return a unique ID."""
171 """Return the current temperature."""
176 """Return the temperature we try to reach."""
180 """Set new target temperature."""
181 await self.
_set_set(kwargs)
185 """Return the current state."""
188 ret
in (HVACAction.COOLING, HVACAction.HEATING)
189 and self.
devicedevicedevice.support_compressor_frequency
192 return HVACAction.IDLE
197 """Return current operation ie. heat, cool, idle."""
198 daikin_mode = self.
devicedevicedevice.represent(HA_ATTR_TO_DAIKIN[ATTR_HVAC_MODE])[1]
199 return DAIKIN_TO_HA_STATE.get(daikin_mode, HVACMode.HEAT_COOL)
203 await self.
_set_set({ATTR_HVAC_MODE: hvac_mode})
207 """Return the fan setting."""
208 return self.
devicedevicedevice.represent(HA_ATTR_TO_DAIKIN[ATTR_FAN_MODE])[1].title()
212 await self.
_set_set({ATTR_FAN_MODE: fan_mode})
216 """Return the fan setting."""
217 return self.
devicedevicedevice.represent(HA_ATTR_TO_DAIKIN[ATTR_SWING_MODE])[1].title()
220 """Set new target temperature."""
221 await self.
_set_set({ATTR_SWING_MODE: swing_mode})
225 """Return the preset_mode."""
227 self.
devicedevicedevice.represent(HA_ATTR_TO_DAIKIN[ATTR_PRESET_MODE])[1]
228 == HA_PRESET_TO_DAIKIN[PRESET_AWAY]
232 HA_PRESET_TO_DAIKIN[PRESET_BOOST]
233 in self.
devicedevicedevice.represent(DAIKIN_ATTR_ADVANCED)[1]
237 HA_PRESET_TO_DAIKIN[PRESET_ECO]
238 in self.
devicedevicedevice.represent(DAIKIN_ATTR_ADVANCED)[1]
244 """Set preset mode."""
245 if preset_mode == PRESET_AWAY:
246 await self.
devicedevicedevice.set_holiday(ATTR_STATE_ON)
247 elif preset_mode == PRESET_BOOST:
249 HA_PRESET_TO_DAIKIN[PRESET_BOOST], ATTR_STATE_ON
251 elif preset_mode == PRESET_ECO:
253 HA_PRESET_TO_DAIKIN[PRESET_ECO], ATTR_STATE_ON
256 await self.
devicedevicedevice.set_holiday(ATTR_STATE_OFF)
259 HA_PRESET_TO_DAIKIN[PRESET_BOOST], ATTR_STATE_OFF
263 HA_PRESET_TO_DAIKIN[PRESET_ECO], ATTR_STATE_OFF
269 """List of available preset modes."""
272 ret.append(PRESET_AWAY)
274 ret += [PRESET_ECO, PRESET_BOOST]
278 """Turn device on."""
283 """Turn device off."""
285 {HA_ATTR_TO_DAIKIN[ATTR_HVAC_MODE]: HA_STATE_TO_DAIKIN[HVACMode.OFF]}
HVACMode|None hvac_mode(self)
str|None preset_mode(self)
None async_set_fan_mode(self, str fan_mode)
None async_set_temperature(self, **Any kwargs)
float|None target_temperature(self)
HVACAction|None hvac_action(self)
None async_set_preset_mode(self, str preset_mode)
float|None current_temperature(self)
None async_turn_off(self)
None __init__(self, DaikinCoordinator coordinator)
None async_set_hvac_mode(self, HVACMode hvac_mode)
None async_set_swing_mode(self, str swing_mode)
None _set(self, dict[str, Any] settings)
list[str] preset_modes(self)
web.Response get(self, web.Request request, str config_key)
str format_target_temperature(float target_temperature)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)