Skip to content

Commit

Permalink
Add duotecno climate (home-assistant#99333)
Browse files Browse the repository at this point in the history
* 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
cereal2nd and joostlek authored Sep 25, 2023
1 parent 2a44364 commit 19854de
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 2 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ omit =
homeassistant/components/duotecno/switch.py
homeassistant/components/duotecno/cover.py
homeassistant/components/duotecno/light.py
homeassistant/components/duotecno/climate.py
homeassistant/components/dwd_weather_warnings/const.py
homeassistant/components/dwd_weather_warnings/coordinator.py
homeassistant/components/dwd_weather_warnings/sensor.py
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/duotecno/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

from .const import DOMAIN

PLATFORMS: list[Platform] = [Platform.SWITCH, Platform.COVER, Platform.LIGHT]
PLATFORMS: list[Platform] = [
Platform.SWITCH,
Platform.COVER,
Platform.LIGHT,
Platform.CLIMATE,
]


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
Expand Down
92 changes: 92 additions & 0 deletions homeassistant/components/duotecno/climate.py
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."""
3 changes: 2 additions & 1 deletion homeassistant/components/duotecno/const.py
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"
16 changes: 16 additions & 0 deletions homeassistant/components/duotecno/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,21 @@
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
}
},
"entity": {
"climate": {
"duotecno": {
"state_attributes": {
"preset_mode": {
"state": {
"sun": "Sun",
"half_sun": "Half sun",
"moon": "Moon",
"half_moon": "Half moon"
}
}
}
}
}
}
}

0 comments on commit 19854de

Please sign in to comment.