forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add duotecno climate (home-assistant#99333)
* Add duotecno climate * Add climate to .coveragerc * Update homeassistant/components/duotecno/climate.py Co-authored-by: Joost Lekkerkerker <[email protected]> * Update homeassistant/components/duotecno/climate.py Co-authored-by: Joost Lekkerkerker <[email protected]> * more comments * more comments * more comments * more comments * fix typo * Add translation key --------- Co-authored-by: Joost Lekkerkerker <[email protected]>
- Loading branch information
Showing
5 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
"""Support for Duotecno climate devices.""" | ||
from typing import Any, Final | ||
|
||
from duotecno.unit import SensUnit | ||
|
||
from homeassistant.components.climate import ( | ||
ClimateEntity, | ||
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 .const import DOMAIN | ||
from .entity import DuotecnoEntity, api_call | ||
|
||
HVACMODE: Final = { | ||
0: HVACMode.OFF, | ||
1: HVACMode.HEAT, | ||
2: HVACMode.COOL, | ||
} | ||
HVACMODE_REVERSE: Final = {value: key for key, value in HVACMODE.items()} | ||
|
||
PRESETMODES: Final = { | ||
"sun": 0, | ||
"half_sun": 1, | ||
"moon": 2, | ||
"half_moon": 3, | ||
} | ||
PRESETMODES_REVERSE: Final = {value: key for key, value in PRESETMODES.items()} | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
entry: ConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
"""Set up Duotecno climate based on config_entry.""" | ||
cntrl = hass.data[DOMAIN][entry.entry_id] | ||
async_add_entities( | ||
DuotecnoClimate(channel) for channel in cntrl.get_units(["SensUnit"]) | ||
) | ||
|
||
|
||
class DuotecnoClimate(DuotecnoEntity, ClimateEntity): | ||
"""Representation of a Duotecno climate entity.""" | ||
|
||
_unit: SensUnit | ||
_attr_supported_features = ( | ||
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE | ||
) | ||
_attr_temperature_unit = UnitOfTemperature.CELSIUS | ||
_attr_hvac_modes = list(HVACMODE_REVERSE) | ||
_attr_preset_modes = list(PRESETMODES) | ||
_attr_translation_key = "duotecno" | ||
|
||
@property | ||
def current_temperature(self) -> int | None: | ||
"""Get the current temperature.""" | ||
return self._unit.get_cur_temp() | ||
|
||
@property | ||
def target_temperature(self) -> float | None: | ||
"""Get the target temperature.""" | ||
return self._unit.get_target_temp() | ||
|
||
@property | ||
def hvac_mode(self) -> HVACMode: | ||
"""Get the current hvac_mode.""" | ||
return HVACMODE[self._unit.get_state()] | ||
|
||
@property | ||
def preset_mode(self) -> str: | ||
"""Get the preset mode.""" | ||
return PRESETMODES_REVERSE[self._unit.get_preset()] | ||
|
||
@api_call | ||
async def async_set_temperature(self, **kwargs: Any) -> None: | ||
"""Set new target temperatures.""" | ||
if (temp := kwargs.get(ATTR_TEMPERATURE)) is None: | ||
return | ||
await self._unit.set_temp(temp) | ||
|
||
@api_call | ||
async def async_set_preset_mode(self, preset_mode: str) -> None: | ||
"""Set the preset mode.""" | ||
await self._unit.set_preset(PRESETMODES[preset_mode]) | ||
|
||
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None: | ||
"""Duotecno does not support setting this, we can only display it.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
"""Constants for the duotecno integration.""" | ||
from typing import Final | ||
|
||
DOMAIN = "duotecno" | ||
DOMAIN: Final = "duotecno" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters