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.
- Loading branch information
Александр Тумайкин
authored and
Александр Тумайкин
committed
May 25, 2021
1 parent
6e2ebd8
commit 4f81487
Showing
7 changed files
with
292 additions
and
5 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
196 changes: 196 additions & 0 deletions
196
custom_components/electrolux_remote/climate_devices/regency.py
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,196 @@ | ||
"""Regency to Climate class""" | ||
|
||
import logging | ||
|
||
from typing import Any, Dict, Optional | ||
|
||
from ..const import DEVICE_REGENCY | ||
from .base import ClimateBase | ||
from..enums import State | ||
from ..devices.regency import ( | ||
Regency, | ||
TEMP_MIN, | ||
TEMP_MAX, | ||
) | ||
from ..update_coordinator import Coordinator | ||
|
||
from homeassistant.components.climate.const import ( | ||
SUPPORT_TARGET_TEMPERATURE, | ||
HVAC_MODE_HEAT, | ||
HVAC_MODE_OFF, | ||
CURRENT_HVAC_HEAT, | ||
CURRENT_HVAC_OFF, | ||
) | ||
|
||
from homeassistant.const import ( | ||
ATTR_TEMPERATURE, | ||
PRECISION_TENTHS, | ||
) | ||
|
||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | ||
|
||
""" | ||
Supported hvac modes: | ||
- HVAC_MODE_HEAT: Heat to a target temperature (schedule off) | ||
- HVAC_MODE_OFF: The device runs in a continuous energy savings mode. If | ||
configured as one of the supported hvac modes this mode | ||
can be used to activate the vacation mode | ||
""" | ||
SUPPORT_MODES = [HVAC_MODE_HEAT, HVAC_MODE_OFF] | ||
|
||
DEFAULT_NAME = "Regency" | ||
|
||
|
||
class RegencyClimate(ClimateBase): | ||
""" | ||
Representation of a climate device | ||
""" | ||
|
||
def __init__(self, uid: str, coordinator: Coordinator): | ||
""" | ||
Initialize the climate device | ||
""" | ||
self.coordinator = coordinator | ||
|
||
super().__init__( | ||
coordinator=coordinator, | ||
uid=uid, | ||
name=DEFAULT_NAME, | ||
support_flags=SUPPORT_FLAGS, | ||
support_modes=SUPPORT_MODES, | ||
support_presets=[], | ||
device=Regency() | ||
) | ||
|
||
@staticmethod | ||
def device_type() -> str: | ||
return DEVICE_REGENCY | ||
|
||
@property | ||
def hvac_mode(self): | ||
"""Return hvac operation """ | ||
if self._device.state: | ||
return HVAC_MODE_HEAT | ||
return HVAC_MODE_OFF | ||
|
||
async def async_set_hvac_mode(self, hvac_mode): | ||
"""Set new target hvac mode.""" | ||
|
||
if hvac_mode == HVAC_MODE_HEAT: | ||
params = {"state": State.ON.value} | ||
elif hvac_mode == HVAC_MODE_OFF: | ||
params = {"state": State.OFF.value} | ||
else: | ||
return | ||
|
||
result = await self.coordinator.api.set_device_params(self._uid, params) | ||
|
||
if result: | ||
self._update_coordinator_data(params) | ||
|
||
@property | ||
def hvac_action(self) -> Optional[str]: | ||
"""Return the current running hvac operation if supported. Need to be one of CURRENT_HVAC_*. """ | ||
if self._device.state: | ||
return CURRENT_HVAC_HEAT | ||
return CURRENT_HVAC_OFF | ||
|
||
async def async_set_temperature(self, **kwargs) -> None: | ||
"""Set new target temperature.""" | ||
|
||
target_temperature = kwargs.get(ATTR_TEMPERATURE) | ||
if target_temperature is None: | ||
return | ||
|
||
if (target_temperature < self.min_temp or | ||
target_temperature > self.max_temp): | ||
_LOGGER.warning( | ||
"%s: set target temperature to %s°C is not supported. " | ||
"The temperature can be set between %s°C and %s°C", | ||
self._name, str(target_temperature), | ||
self.min_temp, self.max_temp) | ||
return | ||
|
||
params = {"temp_goal": target_temperature} | ||
result = await self.coordinator.api.set_device_params(self._uid, params) | ||
|
||
if result: | ||
self._update_coordinator_data(params) | ||
|
||
@property | ||
def precision(self): | ||
return PRECISION_TENTHS | ||
|
||
@property | ||
def device_state_attributes(self) -> Dict[str, Any]: | ||
""" | ||
Return additional Thermostat status details | ||
The information will be available in Home Assistant for reporting | ||
or automations based on teh provided information | ||
""" | ||
return { | ||
"clock_hours": self._device.clock_hours, | ||
"clock_minutes": self._device.clock_minutes, | ||
"room": self._device.room, | ||
} | ||
|
||
async def async_turn_on(self) -> None: | ||
"""Turn the entity on.""" | ||
if self._device.state: | ||
return | ||
|
||
params = {"state": State.ON.value} | ||
|
||
result = await self.coordinator.api.set_device_params(self._uid, params) | ||
|
||
if result: | ||
self._update_coordinator_data(params) | ||
|
||
async def async_turn_off(self) -> None: | ||
"""Turn the entity off.""" | ||
if not self._device.state: | ||
return | ||
|
||
params = {"state": State.OFF.value} | ||
|
||
result = await self.coordinator.api.set_device_params(self._uid, params) | ||
|
||
if result: | ||
self._update_coordinator_data(params) | ||
|
||
@property | ||
def available(self) -> bool: | ||
"""Return if entity is available.""" | ||
return self._device.online | ||
|
||
@property | ||
def current_temperature(self) -> Optional[float]: | ||
"""Return the current temperature.""" | ||
return self._device.current_temp | ||
|
||
@property | ||
def target_temperature(self) -> Optional[float]: | ||
"""Return the temperature we try to reach.""" | ||
return self._device.temp_goal | ||
|
||
@property | ||
def min_temp(self) -> float: | ||
"""Return the minimum temperature.""" | ||
return TEMP_MIN | ||
|
||
@property | ||
def max_temp(self) -> float: | ||
"""Return the maximum temperature.""" | ||
return TEMP_MAX | ||
|
||
def _update(self) -> None: | ||
""" | ||
Update local data | ||
""" | ||
for data in self.coordinator.data: | ||
if data["uid"] == self._uid: | ||
self._device.from_json(data) | ||
|
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 |
---|---|---|
|
@@ -29,3 +29,4 @@ | |
DEVICE_CONVECTOR24 = "convector24" | ||
DEVICE_SMART = "smart" | ||
DEVICE_FLOOR = "floor" | ||
DEVICE_REGENCY = "regency" |
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,54 @@ | ||
"""Regency class (type=regency)""" | ||
|
||
import logging | ||
|
||
from ..enums import State | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
TEMP_MIN = 35 | ||
TEMP_MAX = 75 | ||
|
||
|
||
class Regency: | ||
def __init__(self): | ||
self._state = State.OFF.value | ||
self._online = State.OFF.value | ||
self._room = None # название помещения | ||
self._current_temp = 75 | ||
self._temp_goal = 75 | ||
self._clock_hours = 0 | ||
self._clock_minutes = 0 | ||
|
||
def from_json(self, data: dict): | ||
"""Fill self from json data""" | ||
for key in data: | ||
setattr(self, f"_{key}", data[key]) | ||
|
||
@property | ||
def room(self) -> str: | ||
return self._room | ||
|
||
@property | ||
def online(self) -> bool: | ||
return int(self._online) == State.ON.value | ||
|
||
@property | ||
def clock_hours(self) -> int: | ||
return int(self._clock_hours) | ||
|
||
@property | ||
def clock_minutes(self) -> int: | ||
return int(self._clock_minutes) | ||
|
||
@property | ||
def temp_goal(self) -> int: | ||
return int(self._temp_goal) | ||
|
||
@property | ||
def current_temp(self) -> float: | ||
return float(self._current_temp) | ||
|
||
@property | ||
def state(self) -> bool: | ||
return int(self._state) != State.OFF.value |
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