diff --git a/.gitignore b/.gitignore index c7e6bf3c..601f952f 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ /.pylint.d/ /*_mj.py /.idea/* +build diff --git a/changelog.txt b/changelog.txt index 83f715e8..4cd6cca4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,8 @@ +Version 0.0.21 (2021-12-15) +- Fix number set_state +- Update ignore list +- Fix select entity + Version 0.0.20 (2021-12-14) - Move caches to classes diff --git a/hahomematic/const.py b/hahomematic/const.py index a22dc914..d0b9a6ae 100644 --- a/hahomematic/const.py +++ b/hahomematic/const.py @@ -151,6 +151,7 @@ "QUICK_VETO_TIME", "RELOCK_DELAY", "SECTION", + "SENSOR_ERROR", "SET_SYMBOL_FOR_HEATING_PHASE", "STATE_UNCERTAIN", "SWITCH_POINT_OCCURED", diff --git a/hahomematic/devices/climate.py b/hahomematic/devices/climate.py index c68ccc6f..5e834b7d 100644 --- a/hahomematic/devices/climate.py +++ b/hahomematic/devices/climate.py @@ -81,17 +81,17 @@ def __init__( @property def _humidity(self) -> int | None: """Return the humidity of the device.""" - return self._get_entity_value(FIELD_HUMIDITY) + return self._get_entity_state(FIELD_HUMIDITY) @property def _temperature(self) -> float | None: """Return the temperature of the device.""" - return self._get_entity_value(FIELD_TEMPERATURE) + return self._get_entity_state(FIELD_TEMPERATURE) @property def _setpoint(self) -> float | None: """Return the setpoint of the device.""" - return self._get_entity_value(FIELD_SETPOINT) + return self._get_entity_state(FIELD_SETPOINT) @property def temperature_unit(self) -> str: @@ -190,12 +190,12 @@ class RfThermostat(BaseClimateEntity): @property def _boost_mode(self) -> bool | None: """Return the boost_mode of the device.""" - return self._get_entity_value(FIELD_BOOST_MODE) + return self._get_entity_state(FIELD_BOOST_MODE) @property def _control_mode(self) -> int | None: """Return the control_mode of the device.""" - return self._get_entity_value(FIELD_CONTROL_MODE) + return self._get_entity_state(FIELD_CONTROL_MODE) @property def supported_features(self) -> int: @@ -268,19 +268,19 @@ class IPThermostat(BaseClimateEntity): @property def _set_point_mode(self) -> int | None: - return self._get_entity_value(FIELD_SET_POINT_MODE) + return self._get_entity_state(FIELD_SET_POINT_MODE) @property def _control_mode(self) -> int | None: - return self._get_entity_value(FIELD_CONTROL_MODE) + return self._get_entity_state(FIELD_CONTROL_MODE) @property def _boost_mode(self) -> bool | None: - return self._get_entity_value(FIELD_BOOST_MODE) + return self._get_entity_state(FIELD_BOOST_MODE) @property def _party_mode(self) -> bool | None: - return self._get_entity_value(FIELD_PARTY_MODE) + return self._get_entity_state(FIELD_PARTY_MODE) @property def supported_features(self) -> int: diff --git a/hahomematic/devices/cover.py b/hahomematic/devices/cover.py index 711a7a34..c8b5d1a1 100644 --- a/hahomematic/devices/cover.py +++ b/hahomematic/devices/cover.py @@ -75,12 +75,12 @@ def __init__( @property def _level(self) -> float | None: """Return the level of the cover.""" - return self._get_entity_value(FIELD_LEVEL) + return self._get_entity_state(FIELD_LEVEL) @property def _channel_level(self) -> float | None: """Return the channel level state of the cover.""" - channel_level = self._get_entity_value(FIELD_CHANNEL_LEVEL) + channel_level = self._get_entity_state(FIELD_CHANNEL_LEVEL) if channel_level: return float(channel_level) return self._level @@ -133,12 +133,12 @@ class HmBlind(HmCover): @property def _level_2(self) -> float | None: """Return the level of the tilt.""" - return self._get_entity_value(FIELD_LEVEL_2) + return self._get_entity_state(FIELD_LEVEL_2) @property def _channel_level_2(self) -> float | None: """Return the channel level of the tilt.""" - channel_level_2 = self._get_entity_value(FIELD_CHANNEL_LEVEL_2) + channel_level_2 = self._get_entity_state(FIELD_CHANNEL_LEVEL_2) if channel_level_2: return float(channel_level_2) return self._level_2 @@ -210,7 +210,7 @@ def __init__( @property def _door_state(self) -> int | None: """Return the state of the garage door.""" - return self._get_entity_value(FIELD_DOOR_STATE) + return self._get_entity_state(FIELD_DOOR_STATE) @property def current_cover_position(self) -> int | None: diff --git a/hahomematic/devices/light.py b/hahomematic/devices/light.py index 464c0d66..fd817103 100644 --- a/hahomematic/devices/light.py +++ b/hahomematic/devices/light.py @@ -109,12 +109,12 @@ class HmDimmer(BaseHmLight): @property def _level(self) -> float | None: """Return the dim level of the device.""" - return self._get_entity_value(FIELD_LEVEL) + return self._get_entity_state(FIELD_LEVEL) @property def _channel_level(self) -> float | None: """Return the channel level of the device.""" - return self._get_entity_value(FIELD_CHANNEL_LEVEL) + return self._get_entity_state(FIELD_CHANNEL_LEVEL) @property def is_on(self) -> bool: @@ -165,12 +165,12 @@ class HmLight(BaseHmLight): @property def _state(self) -> bool | None: """Return the state of the light.""" - return self._get_entity_value(FIELD_STATE) + return self._get_entity_state(FIELD_STATE) @property def _channel_state(self) -> bool | None: """Return the channel state of the light.""" - return self._get_entity_value(FIELD_CHANNEL_STATE) + return self._get_entity_state(FIELD_CHANNEL_STATE) @property def is_on(self) -> bool: @@ -212,22 +212,22 @@ class IPLightBSL(BaseHmLight): @property def _color(self) -> str | None: """Return the color of the device.""" - return self._get_entity_value(FIELD_COLOR) + return self._get_entity_state(FIELD_COLOR) @property def _channel_color(self) -> str | None: """Return the channel color of the device.""" - return self._get_entity_value(FIELD_CHANNEL_COLOR) + return self._get_entity_state(FIELD_CHANNEL_COLOR) @property def _level(self) -> float | None: """Return the level of the device.""" - return self._get_entity_value(FIELD_LEVEL) + return self._get_entity_state(FIELD_LEVEL) @property def _channel_level(self) -> float | None: """Return the channel level state of the device.""" - return self._get_entity_value(FIELD_CHANNEL_LEVEL) + return self._get_entity_state(FIELD_CHANNEL_LEVEL) @property def is_on(self) -> bool: @@ -281,7 +281,7 @@ def extra_state_attributes(self) -> dict[str, Any]: state_attr[ATTR_COLOR_NAME] = self._color if self._channel_level and self._channel_level != self._level: state_attr[ATTR_CHANNEL_LEVEL] = self._channel_level * 255 - if self._channel_color and self._channel_color != self._color: + if self._channel_color and self._channel_color: state_attr[ATTR_CHANNEL_COLOR] = self._channel_color return state_attr diff --git a/hahomematic/devices/lock.py b/hahomematic/devices/lock.py index 387c56ca..a150adf3 100644 --- a/hahomematic/devices/lock.py +++ b/hahomematic/devices/lock.py @@ -83,7 +83,7 @@ class IpLock(BaseLock): @property def _lock_state(self) -> float | None: """Return the level of the device.""" - return self._get_entity_value(FIELD_LOCK_STATE) + return self._get_entity_state(FIELD_LOCK_STATE) @property def is_locked(self) -> bool: @@ -109,7 +109,7 @@ class RfLock(BaseLock): @property def _state(self) -> bool | None: """Return the level of the device.""" - return self._get_entity_value(FIELD_STATE) + return self._get_entity_state(FIELD_STATE) @property def is_locked(self) -> bool: diff --git a/hahomematic/devices/switch.py b/hahomematic/devices/switch.py index bdf7de33..84e01bf0 100644 --- a/hahomematic/devices/switch.py +++ b/hahomematic/devices/switch.py @@ -53,12 +53,12 @@ def __init__( @property def _state(self) -> bool | None: """Return the temperature of the device.""" - return self._get_entity_value(FIELD_STATE) + return self._get_entity_state(FIELD_STATE) @property def _channel_state(self) -> bool | None: """Return the temperature of the device.""" - return self._get_entity_value(FIELD_CHANNEL_STATE) + return self._get_entity_state(FIELD_CHANNEL_STATE) @property def state(self) -> bool | None: diff --git a/hahomematic/entity.py b/hahomematic/entity.py index 337362ad..2dce9a51 100644 --- a/hahomematic/entity.py +++ b/hahomematic/entity.py @@ -7,7 +7,7 @@ from collections.abc import Callable from datetime import datetime import logging -from typing import Any, Generic, TypeVar +from typing import Any, Generic, TypeVar, Union import hahomematic.central_unit as hm_central import hahomematic.client as hm_client @@ -50,7 +50,7 @@ import hahomematic.proxy as hm_proxy _LOGGER = logging.getLogger(__name__) -ParameterType = TypeVar("ParameterType", bool, int, float, str, None) +ParameterType = TypeVar("ParameterType", bool, int, float, str, Union[int, str], None) class CallbackEntity(ABC): @@ -496,7 +496,11 @@ async def load_data(self) -> int: self.update_entity() return DATA_LOAD_SUCCESS - def _get_entity_value( + def _get_entity(self, field_name: str) -> GenericEntity | None: + """get entity""" + return self.data_entities.get(field_name) + + def _get_entity_state( self, field_name: str, default: Any | None = None ) -> Any | None: """get entity value""" diff --git a/hahomematic/platforms/number.py b/hahomematic/platforms/number.py index 30857a8f..afa43116 100644 --- a/hahomematic/platforms/number.py +++ b/hahomematic/platforms/number.py @@ -40,7 +40,7 @@ def __init__( async def set_state(self, value: float) -> None: """Set the state of the entity.""" # pylint: disable=no-else-return - if value and self._min <= value <= self._max: + if value is not None and self._min <= value <= self._max: await self.send_value(value) return elif self._special: diff --git a/hahomematic/platforms/select.py b/hahomematic/platforms/select.py index f04f0711..2e79431a 100644 --- a/hahomematic/platforms/select.py +++ b/hahomematic/platforms/select.py @@ -5,7 +5,7 @@ from __future__ import annotations import logging -from typing import Any +from typing import Any, Union from hahomematic.const import HmPlatform import hahomematic.device as hm_device @@ -14,7 +14,7 @@ _LOGGER = logging.getLogger(__name__) -class HmSelect(GenericEntity[int]): +class HmSelect(GenericEntity[Union[int, str]]): """ Implementation of a select entity. This is a default platform that gets automatically generated. @@ -38,10 +38,10 @@ def __init__( ) @property - def value(self) -> str | None: + def state(self) -> str | None: """Get the state of the entity.""" if self._value_list and self._state: - return self._value_list[self._state] + return self._value_list[int(self._state)] return None async def set_state(self, value: int | str) -> None: diff --git a/setup.py b/setup.py index e1c5616a..848359f7 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ def readme(): }, PACKAGE_NAME = "hahomematic" HERE = os.path.abspath(os.path.dirname(__file__)) -VERSION = "0.0.20" +VERSION = "0.0.21" PACKAGES = find_packages(exclude=["tests", "tests.*", "dist", "build"])