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

Commit

Permalink
fix: небольшие доработки
Browse files Browse the repository at this point in the history
  • Loading branch information
Александр Тумайкин authored and Александр Тумайкин committed May 20, 2021
1 parent 4996dcb commit 094fba0
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 21 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

## Features
Поддерживаются устройства Electrolux и Ballu:
- конвекторы (техническое обозначение: conv и convector24)
- термостат ETS-16
- бойлеры (centurio и smart)
- конвекторы Electrolux с блоком управления Transformer Electronic
- конвекторы Ballu с блоком управления Transformer Digital Inverter
- термостат Electrolux ETS-16
- бойлеры (Сenturio IQ, Centurio IQ 2.0, Smart)

## Screenshot
<img src="/~https://github.com/Ailme/home_assistant_electrolux_remote/blob/main/img/img-1.png?raw=true" width="250">
Expand Down
13 changes: 7 additions & 6 deletions custom_components/electrolux_remote/climate_devices/centurio2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
TEMP_MAX,
)
from ..update_coordinator import Coordinator
from ..enums import State

from homeassistant.components.climate.const import (
SUPPORT_TARGET_TEMPERATURE,
Expand All @@ -38,7 +39,6 @@
PRESET_II = 'II'
PRESET_III = 'III'
PRESET_NO_FROST = 'NO_FROST'
PRESET_SELF_CLEAN = 'SELF_CLEAN'


SUPPORT_PRESETS = [
Expand All @@ -47,7 +47,6 @@
PRESET_II,
PRESET_III,
PRESET_NO_FROST,
PRESET_SELF_CLEAN
]

"""
Expand All @@ -65,7 +64,6 @@
PRESET_II: WaterMode.II.value,
PRESET_III: WaterMode.III.value,
PRESET_NO_FROST: WaterMode.NO_FROST.value,
PRESET_SELF_CLEAN: WaterMode.SELF_CLEAN.value,
}
DEVICE_PRESET_TO_HA = {v: k for k, v in HA_PRESET_TO_DEVICE.items()}

Expand All @@ -82,6 +80,7 @@ def __init__(self, uid: str, coordinator: Coordinator):
Initialize the climate device
"""
self.coordinator = coordinator
self._prev_mode = WaterMode.OFF.value

super().__init__(
coordinator=coordinator,
Expand All @@ -100,16 +99,18 @@ def device_type() -> str:
@property
def hvac_mode(self):
"""Return hvac operation """
if self.preset_mode == PRESET_OFF:
if self.preset_mode == PRESET_OFF and not self._device.timer:
return HVAC_MODE_OFF
return HVAC_MODE_HEAT

async def async_set_hvac_mode(self, hvac_mode):
"""Set new target hvac mode."""
if hvac_mode == HVAC_MODE_HEAT:
params = {"mode": WaterMode.I.value}
params = {"mode": self._prev_mode if self._prev_mode > 0 else WaterMode.I.value}
elif hvac_mode == HVAC_MODE_OFF:
params = {"mode": WaterMode.OFF.value}
self._prev_mode = self._device.mode

params = {"mode": WaterMode.OFF.value, "timer": State.OFF.value}
else:
return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ..devices.convector2 import (
Convector2,
WorkMode,
HeatMode,
TEMP_MIN,
TEMP_MAX,
TEMP_ANTIFROST_MIN,
Expand Down Expand Up @@ -97,10 +98,13 @@ def hvac_mode(self):

async def async_set_hvac_mode(self, hvac_mode):
"""Set new target hvac mode."""
_LOGGER.debug(f"{hvac_mode}, {self._device.heat_mode_auto}")
if hvac_mode == HVAC_MODE_AUTO and not self._device.state:
params = {"state": State.ON.value}
params = {"state": State.ON.value, "heat_mode": HeatMode.AUTO.value}
elif hvac_mode == HVAC_MODE_AUTO and self._device.state:
params = {"heat_mode": 1 - self._device.heat_mode}
elif hvac_mode == HVAC_MODE_HEAT and self._device.heat_mode_auto:
params = {"state": State.ON.value, "heat_mode": HeatMode.MANUAL.value}
elif hvac_mode == HVAC_MODE_HEAT:
params = {"state": State.ON.value}
elif hvac_mode == HVAC_MODE_OFF:
Expand Down
5 changes: 2 additions & 3 deletions custom_components/electrolux_remote/devices/centurio2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

_LOGGER = logging.getLogger(__name__)

TEMP_MIN = 30
TEMP_MIN = 35
TEMP_MAX = 75


Expand All @@ -24,8 +24,7 @@ class WaterMode(IntEnum):
I = 1
II = 2
III = 3
NO_FROST = 4
SELF_CLEAN = 5
NO_FROST = 5
NO_CONNECTION = 6


Expand Down
125 changes: 117 additions & 8 deletions custom_components/electrolux_remote/switch_devices/centurio2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import logging

from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.components.switch import SwitchEntity, ENTITY_ID_FORMAT
from homeassistant.helpers.entity import async_generate_entity_id

from .base import SwitchDevice
from ..enums import State
from ..devices.centurio2 import Centurio2
from ..devices.centurio2 import Centurio2, WaterMode
from ..update_coordinator import Coordinator
from ..const import DEVICE_CENTURIO2

Expand All @@ -24,8 +28,8 @@ def __init__(self, uid: str, coordinator: Coordinator):
uid=uid,
coordinator=coordinator,
name=f"Bacteria stop system",
icon_on="",
icon_off="",
icon_on="mdi:alien",
icon_off="mdi:alien-outline",
device=device,
param_name="self_clean",
property_name="self_clean",
Expand All @@ -36,14 +40,21 @@ def __init__(self, uid: str, coordinator: Coordinator):
SwitchDevice(
uid=uid,
coordinator=coordinator,
name=f"Timer",
icon_on="mdi:timer",
icon_off="mdi:timer",
name=f"Economy pause",
icon_on="",
icon_off="",
device=device,
param_name="timer",
property_name="timer",
param_name="economy_pause",
property_name="economy_pause",
value_on=State.ON.value,
value_off=State.OFF.value
),

Timer(
uid=uid,
coordinator=coordinator,
name=f"Timer",
device=device,
)
]

Expand All @@ -53,3 +64,101 @@ def device_type() -> str:

def get_sensors(self):
return self.switches


class Timer(CoordinatorEntity, SwitchEntity):
def __init__(
self,
uid: str,
name: str,
coordinator: Coordinator,
device
):
"""
Initialize
"""
self.coordinator = coordinator

super().__init__(coordinator)

self._uid = uid
self._name = f"{name} {uid}"
self._device = device

self.entity_id = async_generate_entity_id(
f"{ENTITY_ID_FORMAT}", self._name, current_ids=[uid]
)

coordinator.async_add_listener(self._update)
self._update()

@property
def name(self):
"""Return the name."""
return self._name

@property
def icon(self) -> str:
"""Return the icon to use in the frontend, if any."""
return "mdi:timer"

@property
def is_on(self) -> bool:
"""Return true if the binary_sensor is on."""
return self._device.timer

async def async_turn_on(self, **kwargs):
"""Turn the entity on."""
if self._device.timer:
return

params = {"timer": State.ON.value, "mode": WaterMode.OFF.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.timer:
return

params = {"timer": State.OFF.value, "mode": WaterMode.I.value}

result = await self.coordinator.api.set_device_params(self._uid, params)

if result:
self._update_coordinator_data(params)

async def async_toggle(self) -> None:
"""Turn the entity off."""
if self._device.timer:
params = {"timer": State.OFF.value, "mode": WaterMode.I.value}
else:
params = {"timer": State.ON.value, "mode": WaterMode.OFF.value}

result = await self.coordinator.api.set_device_params(self._uid, params)

if result:
self._update_coordinator_data(params)

def _update(self) -> None:
"""
Update local data
"""
for data in self.coordinator.data:
if data["uid"] == self._uid:
self._device.from_json(data)

def _update_coordinator_data(self, params: dict) -> None:
"""Update data in coordinator"""
devices = self.coordinator.data

for index, device in enumerate(devices):
if device["uid"] == self._uid:
for param in params:
devices[index][param] = params[param]

self.coordinator.async_set_updated_data(devices)
self._update()

0 comments on commit 094fba0

Please sign in to comment.