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

Commit

Permalink
feat: добавлены атрибуты для Climate Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Александр Тумайкин authored and Александр Тумайкин committed Apr 6, 2021
1 parent 3d982ad commit 529dd3d
Show file tree
Hide file tree
Showing 11 changed files with 784 additions and 309 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
## Screenshot
<img src="https://github.com/Ailme/home_assistant_electrolux_remote/blob/main/img/img-1.png?raw=true" width="250">
<img src="https://github.com/Ailme/home_assistant_electrolux_remote/blob/main/img/img-2.png?raw=true" width="250">
<img src="https://github.com/Ailme/home_assistant_electrolux_remote/blob/main/img/img-3.png?raw=true" width="250">
<img src="https://github.com/Ailme/home_assistant_electrolux_remote/blob/main/img/img-3.png?raw=true" width="250">
<img src="https://github.com/Ailme/home_assistant_electrolux_remote/blob/main/img/img-4.png?raw=true" width="250">
47 changes: 28 additions & 19 deletions custom_components/electrolux_remote/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Adds Support for Electrolux Convector
Configuration for this platform:
logger:
default: info
logs:
custom_components.electrolux_remote: debug
climate:
- platform: electrolux_remote
name: Electrolux Convector
Expand All @@ -24,31 +30,34 @@


async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_devices):
"""
Setup the climate platform
"""
_LOGGER.debug("climate.async_setup_entry")

data = config_entry.options if config_entry.options != {} else config_entry.data
devices = []

_LOGGER.debug("climate.async_setup_entry")

api = RusclimatApi(
host=data["host"],
username=data["username"],
password=data["password"],
appcode=data["appcode"],
)
json = await api.login()
try:
api = TestApi(
host=data["host"],
username=data["username"],
password=data["password"],
appcode=data["appcode"],
)
json = await api.login()

devices = []
for deviceData in json["result"]["device"]:
_LOGGER.debug(f"device: {deviceData}")
for deviceData in json["result"]["device"]:
_LOGGER.debug(f"device: {deviceData}")

if deviceData["type"] == Convector2Climate.device_type():
device = Convector2Climate(deviceData["uid"], api, deviceData)
devices.append(device)
if deviceData["type"] == Convector2Climate.device_type():
device = Convector2Climate(deviceData["uid"], api, deviceData)
devices.append(device)

if deviceData["type"] == Thermostat2Climate.device_type():
device = Thermostat2Climate(deviceData["uid"], api, deviceData)
devices.append(device)
if deviceData["type"] == Thermostat2Climate.device_type():
device = Thermostat2Climate(deviceData["uid"], api, deviceData)
devices.append(device)
except Exception as err:
_LOGGER.error(err)

_LOGGER.debug(devices)
async_add_devices(devices)
132 changes: 132 additions & 0 deletions custom_components/electrolux_remote/climate_base.py
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
Loading

0 comments on commit 529dd3d

Please sign in to comment.