1 """Support for Freedompro climate."""
3 from __future__
import annotations
9 from aiohttp.client
import ClientSession
10 from pyfreedompro
import put_state
26 from .const
import DOMAIN
27 from .coordinator
import FreedomproDataUpdateCoordinator
29 _LOGGER = logging.getLogger(__name__)
37 HVAC_INVERT_MAP = {v: k
for k, v
in HVAC_MAP.items()}
39 SUPPORTED_HVAC_MODES = [
47 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
49 """Set up Freedompro climate."""
50 api_key: str = entry.data[CONF_API_KEY]
51 coordinator: FreedomproDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
54 aiohttp_client.async_get_clientsession(hass), api_key, device, coordinator
56 for device
in coordinator.data
57 if device[
"type"] ==
"thermostat"
62 """Representation of a Freedompro climate."""
64 _attr_has_entity_name =
True
65 _attr_hvac_modes = SUPPORTED_HVAC_MODES
66 _attr_temperature_unit = UnitOfTemperature.CELSIUS
68 _attr_supported_features = (
69 ClimateEntityFeature.TARGET_TEMPERATURE
70 | ClimateEntityFeature.TURN_OFF
71 | ClimateEntityFeature.TURN_ON
73 _attr_current_temperature = 0
74 _attr_target_temperature = 0
75 _attr_hvac_mode = HVACMode.OFF
76 _enable_turn_on_off_backwards_compatibility =
False
80 session: ClientSession,
82 device: dict[str, Any],
83 coordinator: FreedomproDataUpdateCoordinator,
85 """Initialize the Freedompro climate."""
93 (DOMAIN, device[
"uid"]),
95 manufacturer=
"Freedompro",
102 """Handle updated data from the coordinator."""
106 for device
in self.coordinator.data
111 if device
is not None and "state" in device:
112 state = device[
"state"]
113 if "currentTemperature" in state:
115 if "targetTemperature" in state:
117 if "heatingCoolingState" in state:
118 self.
_attr_hvac_mode_attr_hvac_mode = HVAC_MAP[state[
"heatingCoolingState"]]
122 """When entity is added to hass."""
127 """Async function to set mode to climate."""
128 if hvac_mode
not in SUPPORTED_HVAC_MODES:
129 raise ValueError(f
"Got unsupported hvac_mode {hvac_mode}")
131 payload = {
"heatingCoolingState": HVAC_INVERT_MAP[hvac_mode]}
141 """Async function to set temperature to climate."""
143 if ATTR_HVAC_MODE
in kwargs:
144 if kwargs[ATTR_HVAC_MODE]
not in SUPPORTED_HVAC_MODES:
146 "Got unsupported hvac_mode %s, expected one of %s",
147 kwargs[ATTR_HVAC_MODE],
148 SUPPORTED_HVAC_MODES,
151 payload[
"heatingCoolingState"] = HVAC_INVERT_MAP[kwargs[ATTR_HVAC_MODE]]
152 if ATTR_TEMPERATURE
in kwargs:
153 payload[
"targetTemperature"] = kwargs[ATTR_TEMPERATURE]
None async_set_hvac_mode(self, HVACMode hvac_mode)
None __init__(self, ClientSession session, str api_key, dict[str, Any] device, FreedomproDataUpdateCoordinator coordinator)
_attr_current_temperature
None _handle_coordinator_update(self)
int _attr_target_temperature
int _attr_current_temperature
None async_added_to_hass(self)
None async_set_temperature(self, **Any kwargs)
None async_request_refresh(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)