Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
feat: add electrolux regency
Browse files Browse the repository at this point in the history
  • Loading branch information
Александр Тумайкин authored and Александр Тумайкин committed May 25, 2021
1 parent 6e2ebd8 commit 4f81487
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 5 deletions.
31 changes: 30 additions & 1 deletion custom_components/electrolux_remote/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,34 @@ def __init__(self, host: str, username: str, password: str, appcode: str, sessio
'curr_slot_dropped': '0',
'curr_scene_dropped': '0',
'online': '1'}
regency = {
'tempid': '197924',
'state': '3',
'timezone': '0',
'current_temp': '39',
'temp_goal': '75',
'error': '0',
'type': 'regency',
'code': '0',
'uid': '197924',
'mac': 'set',
'room': 'баня',
'sort': '0',
'curr_slot': '0',
'active_slot': '0',
'slop': '0',
'curr_scene': '0',
'curr_scene_id': '0',
'wait_slot': '0',
'curr_slot_dropped': '0',
'curr_scene_dropped': '0',
'clock_hours': '0',
'clock_minutes': '47',
'timer_hours': '0',
'timer_minutes': '0',
'self_clean': '1',
'online': '1'
}

self.devices = [
floor_1,
Expand All @@ -637,7 +665,8 @@ def __init__(self, host: str, username: str, password: str, appcode: str, sessio
centurio,
convector,
smart,
centurio2
centurio2,
regency
]

async def login(self) -> []:
Expand Down
10 changes: 7 additions & 3 deletions custom_components/electrolux_remote/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from .climate_devices.thermostat import Thermostat2Climate
from .climate_devices.centurio import CenturioClimate
from .climate_devices.centurio2 import Centurio2Climate
from .climate_devices.smart import Smart2Climate
from .climate_devices.smart import SmartClimate
from .climate_devices.regency import RegencyClimate

from .const import DOMAIN
from .update_coordinator import Coordinator
Expand Down Expand Up @@ -45,8 +46,11 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
if deviceData["type"] == Centurio2Climate.device_type():
device = Centurio2Climate(deviceData["uid"], coordinator)

if deviceData["type"] == Smart2Climate.device_type():
device = Smart2Climate(deviceData["uid"], coordinator)
if deviceData["type"] == SmartClimate.device_type():
device = SmartClimate(deviceData["uid"], coordinator)

if deviceData["type"] == RegencyClimate.device_type():
device = RegencyClimate(deviceData["uid"], coordinator)

if device is not None:
_LOGGER.debug(f"add device: {device.name}")
Expand Down
196 changes: 196 additions & 0 deletions custom_components/electrolux_remote/climate_devices/regency.py
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)

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
DEFAULT_NAME = "Smart"


class Smart2Climate(ClimateBase):
class SmartClimate(ClimateBase):
"""
Representation of a climate device
"""
Expand Down
1 change: 1 addition & 0 deletions custom_components/electrolux_remote/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@
DEVICE_CONVECTOR24 = "convector24"
DEVICE_SMART = "smart"
DEVICE_FLOOR = "floor"
DEVICE_REGENCY = "regency"
54 changes: 54 additions & 0 deletions custom_components/electrolux_remote/devices/regency.py
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
3 changes: 3 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ This is **only** intended for development!
{%- elif (version_installed.replace("v", "").split(".")[0] | int) < 1 %}
## Version 0.0.10

### Features
- добавлена поддержка бойлера Electrolux Regency

### Fix
- исправлены ошибки

Expand Down

0 comments on commit 4f81487

Please sign in to comment.