1 """Platform for eQ-3 climate entities."""
6 from eq3btsmart.const
import EQ3BT_MAX_TEMP, EQ3BT_OFF_TEMP, Eq3Preset, OperationMode
7 from eq3btsmart.exceptions
import Eq3Exception
24 from .
import Eq3ConfigEntry
28 CurrentTemperatureSelector,
30 TargetTemperatureSelector,
32 from .entity
import Eq3Entity
34 _LOGGER = logging.getLogger(__name__)
39 entry: Eq3ConfigEntry,
40 async_add_entities: AddEntitiesCallback,
42 """Handle config entry setup."""
50 """Climate entity to represent a eQ-3 thermostat."""
53 _attr_supported_features = (
54 ClimateEntityFeature.TARGET_TEMPERATURE
55 | ClimateEntityFeature.PRESET_MODE
56 | ClimateEntityFeature.TURN_OFF
57 | ClimateEntityFeature.TURN_ON
59 _attr_temperature_unit = UnitOfTemperature.CELSIUS
60 _attr_min_temp = EQ3BT_OFF_TEMP
61 _attr_max_temp = EQ3BT_MAX_TEMP
62 _attr_precision = PRECISION_HALVES
63 _attr_hvac_modes =
list(HA_TO_EQ_HVAC.keys())
64 _attr_preset_modes =
list(Preset)
65 _attr_should_poll =
False
66 _attr_available =
False
67 _attr_hvac_mode: HVACMode |
None =
None
68 _attr_hvac_action: HVACAction |
None =
None
69 _attr_preset_mode: str |
None =
None
70 _target_temperature: float |
None =
None
74 """Handle updated data from the thermostat."""
79 if self.
_thermostat_thermostat.device_data
is not None:
86 """Handle updated status from the thermostat."""
100 """Handle updated device data from the thermostat."""
102 if self.
_thermostat_thermostat.device_data
is None:
105 device_registry = dr.async_get(self.
hasshass)
106 if device := device_registry.async_get_device(
107 connections={(CONNECTION_BLUETOOTH, self.
_eq3_config_eq3_config.mac_address)},
109 device_registry.async_update_device(
111 sw_version=
str(self.
_thermostat_thermostat.device_data.firmware_version),
112 serial_number=self.
_thermostat_thermostat.device_data.device_serial.value,
116 """Return the current temperature."""
118 match self.
_eq3_config_eq3_config.current_temp_selector:
119 case CurrentTemperatureSelector.NOTHING:
121 case CurrentTemperatureSelector.VALVE:
126 case CurrentTemperatureSelector.UI:
128 case CurrentTemperatureSelector.DEVICE:
133 case CurrentTemperatureSelector.ENTITY:
134 state = self.
hasshass.states.get(self.
_eq3_config_eq3_config.external_temp_sensor)
135 if state
is not None:
137 return float(state.state)
144 """Return the target temperature."""
146 match self.
_eq3_config_eq3_config.target_temp_selector:
147 case TargetTemperatureSelector.TARGET:
149 case TargetTemperatureSelector.LAST_REPORTED:
156 """Return the current preset mode."""
158 if (status := self.
_thermostat_thermostat.status)
is None:
160 if status.is_window_open:
161 return Preset.WINDOW_OPEN
164 if status.is_low_battery:
165 return Preset.LOW_BATTERY
168 if status.operation_mode
is OperationMode.ON:
170 if status.presets
is None:
172 if status.target_temperature == status.presets.eco_temperature:
174 if status.target_temperature == status.presets.comfort_temperature:
175 return Preset.COMFORT
180 """Return the current hvac action."""
184 or self.
_thermostat_thermostat.status.operation_mode
is OperationMode.OFF
186 return HVACAction.OFF
188 return HVACAction.IDLE
189 return HVACAction.HEATING
192 """Set new target temperature."""
194 if ATTR_HVAC_MODE
in kwargs:
195 mode: HVACMode |
None
196 if (mode := kwargs.get(ATTR_HVAC_MODE))
is None:
199 if mode
is not HVACMode.OFF:
203 f
"[{self._eq3_config.mac_address}] Can't change HVAC mode to off while changing temperature",
206 temperature: float |
None
207 if (temperature := kwargs.get(ATTR_TEMPERATURE))
is None:
219 "[%s] Failed setting temperature", self.
_eq3_config_eq3_config.mac_address
223 except ValueError
as ex:
227 """Set new target hvac mode."""
229 if hvac_mode
is HVACMode.OFF:
233 await self.
_thermostat_thermostat.async_set_mode(HA_TO_EQ_HVAC[hvac_mode])
235 _LOGGER.error(
"[%s] Failed setting HVAC mode", self.
_eq3_config_eq3_config.mac_address)
238 """Set new preset mode."""
242 await self.
_thermostat_thermostat.async_set_boost(
True)
244 await self.
_thermostat_thermostat.async_set_away(
True)
246 await self.
_thermostat_thermostat.async_set_preset(Eq3Preset.ECO)
248 await self.
_thermostat_thermostat.async_set_preset(Eq3Preset.COMFORT)
250 await self.
_thermostat_thermostat.async_set_mode(OperationMode.ON)
None async_set_temperature(self, **Any kwargs)
None async_set_hvac_mode(self, HVACMode hvac_mode)
None async_set_preset_mode(self, str preset_mode)
None _async_on_status_updated(self)
_attr_current_temperature
str _get_current_preset_mode(self)
None async_set_hvac_mode(self, HVACMode hvac_mode)
None async_set_temperature(self, **Any kwargs)
None _async_on_updated(self)
HVACAction _get_current_hvac_action(self)
float|None _get_target_temperature(self)
None _async_on_device_updated(self)
float|None _get_current_temperature(self)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, Eq3ConfigEntry entry, AddEntitiesCallback async_add_entities)