core/homeassistant/components/intellifire/climate.py

122 lines
3.9 KiB
Python
Raw Permalink Normal View History

"""Intellifire Climate Entities."""
from __future__ import annotations
2022-08-30 17:21:08 +00:00
from typing import Any
from homeassistant.components.climate import (
ClimateEntity,
ClimateEntityDescription,
ClimateEntityFeature,
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import IntellifireDataUpdateCoordinator
from .const import DEFAULT_THERMOSTAT_TEMP, DOMAIN, LOGGER
from .entity import IntellifireEntity
INTELLIFIRE_CLIMATES: tuple[ClimateEntityDescription, ...] = (
ClimateEntityDescription(key="climate", name="Thermostat"),
)
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Configure the fan entry.."""
coordinator: IntellifireDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
if coordinator.data.has_thermostat:
async_add_entities(
IntellifireClimate(
coordinator=coordinator,
description=description,
)
for description in INTELLIFIRE_CLIMATES
)
class IntellifireClimate(IntellifireEntity, ClimateEntity):
"""Intellifire climate entity."""
entity_description: ClimateEntityDescription
_attr_hvac_modes = [HVACMode.HEAT, HVACMode.OFF]
_attr_min_temp = 0
_attr_max_temp = 37
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
)
_attr_target_temperature_step = 1.0
_attr_temperature_unit = UnitOfTemperature.CELSIUS
last_temp = DEFAULT_THERMOSTAT_TEMP
def __init__(
self,
coordinator: IntellifireDataUpdateCoordinator,
description: ClimateEntityDescription,
) -> None:
"""Configure climate entry - and override last_temp if the thermostat is currently on."""
super().__init__(coordinator, description)
if coordinator.data.thermostat_on:
Bump Intellifire to 4.1.9 (#121091) * rebase * Minor patch to fix duplicate DeviceInfo beign created - if data hasnt updated yet * rebase * Minor patch to fix duplicate DeviceInfo beign created - if data hasnt updated yet * fixing formatting * Update homeassistant/components/intellifire/__init__.py Co-authored-by: Erik Montnemery <erik@montnemery.com> * Update homeassistant/components/intellifire/__init__.py Co-authored-by: Erik Montnemery <erik@montnemery.com> * Removing cloud connectivity sensor - leaving local one in * Renaming class to something more useful * addressing pr * Update homeassistant/components/intellifire/__init__.py Co-authored-by: Erik Montnemery <erik@montnemery.com> * add ruff exception * Fix test annotations * remove access to private variable * Bumping to 4.1.9 instead of 4.1.5 * A renaming * rename * Updated testing * Update __init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * updateing styrings * Update tests/components/intellifire/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Testing refactor - WIP * everything is passing - cleanup still needed * cleaning up comments * update pr * unrename * Update homeassistant/components/intellifire/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * fixing sentence * fixed fixture and removed error codes * reverted a bad change * fixing strings.json * revert renaming * fix * typing inother pr * adding extra tests - one has a really dumb name * using a real value * added a migration in * Update homeassistant/components/intellifire/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/intellifire/test_init.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * cleanup continues * addressing pr * switch back to debug * Update tests/components/intellifire/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * some changes * restore property mock cuase didnt work otherwise * cleanup has begun * removed extra text * addressing pr stuff * fixed reauth --------- Co-authored-by: Erik Montnemery <erik@montnemery.com> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-01 10:48:38 +00:00
self.last_temp = int(coordinator.data.thermostat_setpoint_c)
@property
def hvac_mode(self) -> HVACMode:
"""Return current hvac mode."""
if self.coordinator.read_api.data.thermostat_on:
return HVACMode.HEAT
return HVACMode.OFF
2022-08-30 17:21:08 +00:00
async def async_set_temperature(self, **kwargs: Any) -> None:
"""Turn on thermostat by setting a target temperature."""
raw_target_temp = kwargs[ATTR_TEMPERATURE]
self.last_temp = int(raw_target_temp)
LOGGER.debug(
"Setting target temp to %sc %sf",
int(raw_target_temp),
(raw_target_temp * 9 / 5) + 32,
)
await self.coordinator.control_api.set_thermostat_c(
temp_c=self.last_temp,
)
@property
def current_temperature(self) -> float:
"""Return the current temperature."""
return float(self.coordinator.read_api.data.temperature_c)
@property
def target_temperature(self) -> float:
"""Return target temperature."""
return float(self.coordinator.read_api.data.thermostat_setpoint_c)
2022-08-30 17:21:08 +00:00
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set HVAC mode to normal or thermostat control."""
LOGGER.debug(
"Setting mode to [%s] - using last temp: %s", hvac_mode, self.last_temp
)
if hvac_mode == HVACMode.OFF:
await self.coordinator.control_api.turn_off_thermostat()
return
# hvac_mode == HVACMode.HEAT
# 1) Set the desired target temp
await self.coordinator.control_api.set_thermostat_c(
temp_c=self.last_temp,
)
# 2) Make sure the fireplace is on!
if not self.coordinator.read_api.data.is_on:
await self.coordinator.control_api.flame_on()