This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: добавлены атрибуты для Climate Entity
- Loading branch information
Александр Тумайкин
authored and
Александр Тумайкин
committed
Apr 6, 2021
1 parent
3d982ad
commit 529dd3d
Showing
11 changed files
with
784 additions
and
309 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,132 @@ | ||
"""Base to Climate class""" | ||
|
||
import logging | ||
|
||
from abc import abstractmethod | ||
from typing import Any, Dict, List, Optional | ||
from homeassistant.components.climate import ClimateEntity | ||
|
||
from homeassistant.const import ( | ||
TEMP_CELSIUS, | ||
) | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class ClimateBase(ClimateEntity): | ||
""" | ||
Representation of a climate device | ||
""" | ||
|
||
def __init__( | ||
self, | ||
uid: str, | ||
name: str, | ||
temp_min: float, | ||
temp_max: float, | ||
support_flags: int, | ||
support_modes: List[str], | ||
support_presets: List[str], | ||
): | ||
""" | ||
Initialize the climate device | ||
""" | ||
_LOGGER.debug("ClimateBase.init") | ||
|
||
self._icon = "mdi:radiator" | ||
self._uid = uid | ||
self._name = name | ||
self._min_temp = temp_min | ||
self._max_temp = temp_max | ||
self._support_flags = support_flags | ||
self._support_modes = support_modes | ||
self._support_presets = support_presets | ||
|
||
self._current_temp = None | ||
self._preset = None | ||
self._target_temperature = None | ||
self._available = False | ||
|
||
@abstractmethod | ||
def _update(self): | ||
""" | ||
Update local data | ||
""" | ||
raise NotImplementedError() | ||
|
||
@staticmethod | ||
@abstractmethod | ||
def device_type() -> str: | ||
""" | ||
Return device type | ||
""" | ||
raise NotImplementedError() | ||
|
||
@property | ||
def should_poll(self) -> bool: | ||
""" | ||
Polling needed for thermostat | ||
""" | ||
return True | ||
|
||
@property | ||
def hvac_modes(self) -> List[str]: | ||
"""Return the list of available hvac operation modes. Need to be a subset of HVAC_MODES. """ | ||
return self._support_modes | ||
|
||
@property | ||
def available(self) -> bool: | ||
"""Return True if entity is available.""" | ||
return self._available | ||
|
||
@property | ||
def temperature_unit(self) -> str: | ||
"""Return the unit of measurement.""" | ||
return TEMP_CELSIUS | ||
|
||
@property | ||
def unique_id(self) -> str: | ||
"""Return the unique ID of the binary sensor.""" | ||
return self._uid | ||
|
||
@property | ||
def current_temperature(self) -> Optional[float]: | ||
"""Return the current temperature.""" | ||
return self._current_temp | ||
|
||
@property | ||
def min_temp(self) -> float: | ||
"""Return the minimum temperature.""" | ||
if self._min_temp: | ||
return self._min_temp | ||
|
||
@property | ||
def max_temp(self) -> float: | ||
"""Return the maximum temperature.""" | ||
if self._max_temp: | ||
return self._max_temp | ||
|
||
@property | ||
def target_temperature(self) -> Optional[float]: | ||
"""Return the temperature we try to reach.""" | ||
return self._target_temperature | ||
|
||
@property | ||
def preset_mode(self) -> Optional[str]: | ||
"""Return the current preset mode, e.g., home, away, temp.""" | ||
return self._preset | ||
|
||
@property | ||
def name(self) -> str: | ||
"""Return the name of the climate device.""" | ||
return self._name | ||
|
||
@property | ||
def supported_features(self) -> int: | ||
"""Return the list of supported features.""" | ||
return self._support_flags | ||
|
||
@property | ||
def preset_modes(self) -> List[str]: | ||
"""Return a list of available preset modes.""" | ||
return self._support_presets |
Oops, something went wrong.