Skip to content

Commit

Permalink
Fix select entity (#71)
Browse files Browse the repository at this point in the history
- Fix number set_state
- Update ignore list
- Fix select entity
  • Loading branch information
SukramJ authored Dec 15, 2021
1 parent 7cda8eb commit 0ac8ef8
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
/.pylint.d/
/*_mj.py
/.idea/*
build
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions hahomematic/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
"QUICK_VETO_TIME",
"RELOCK_DELAY",
"SECTION",
"SENSOR_ERROR",
"SET_SYMBOL_FOR_HEATING_PHASE",
"STATE_UNCERTAIN",
"SWITCH_POINT_OCCURED",
Expand Down
18 changes: 9 additions & 9 deletions hahomematic/devices/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions hahomematic/devices/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 9 additions & 9 deletions hahomematic/devices/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions hahomematic/devices/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions hahomematic/devices/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 7 additions & 3 deletions hahomematic/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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"""
Expand Down
2 changes: 1 addition & 1 deletion hahomematic/platforms/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions hahomematic/platforms/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down

0 comments on commit 0ac8ef8

Please sign in to comment.