Skip to content

Commit

Permalink
Accept LOWBAT only on channel 0 (#187)
Browse files Browse the repository at this point in the history
* Remove old comments

* Add entity_type to attributes

Rename extra_state_attributes  to attributes

* Update entity.py

* Accept LOWBAT only on channel 0
  • Loading branch information
SukramJ authored Jan 15, 2022
1 parent 9d85521 commit 793810b
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 24 deletions.
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Version 0.22.1 (2022-01-15)
- Add VALVE_STATE for hm climate
- Add entity_type to attributes
- Accept LOWBAT only on channel 0

Version 0.22.0 (2022-01-14)
- Move client management to central
Expand Down
14 changes: 14 additions & 0 deletions hahomematic/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@
"WEEK_PROGRAM",
]

ACCEPT_PARAMETER_ONLY_ON_CHANNEL = {"LOWBAT": 0}

HIDDEN_PARAMETERS = [EVENT_UN_REACH, EVENT_STICKY_UN_REACH, EVENT_CONFIG_PENDING]

BACKEND_CCU = "CCU"
Expand All @@ -172,6 +174,7 @@
ATTR_CALLBACK_HOST = "callback_host"
ATTR_CALLBACK_PORT = "callback_port"
ATTR_CHANNELS = "channels"
ATTR_ENTITY_TYPE = "entity_type"
ATTR_ERROR = "error"
ATTR_HOST = "host"
ATTR_INTERFACE = "interface"
Expand Down Expand Up @@ -288,6 +291,17 @@ def __str__(self) -> str:
return str(self.value)


class HmEntityType(Enum):
"""Enum with hahomematic entity types."""

GENERIC = "generic"
CUSTOM = "custom"

def __str__(self) -> str:
"""Return self.value."""
return str(self.value)


class HmEventType(Enum):
"""Enum with hahomematic event types."""

Expand Down
28 changes: 22 additions & 6 deletions hahomematic/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import hahomematic.central_unit as hm_central
from hahomematic.const import (
ACCEPT_PARAMETER_ONLY_ON_CHANNEL,
ATTR_HM_FIRMWARE,
ATTR_HM_FLAGS,
ATTR_HM_OPERATIONS,
Expand Down Expand Up @@ -51,7 +52,7 @@
GenericEntity,
SpecialEvent,
)
from hahomematic.helpers import generate_unique_id, get_device_name
from hahomematic.helpers import generate_unique_id, get_device_channel, get_device_name
from hahomematic.internal.action import HmAction
from hahomematic.internal.text import HmText
from hahomematic.platforms.binary_sensor import HmBinarySensor
Expand Down Expand Up @@ -456,11 +457,9 @@ def create_entity(
Helper that looks at the paramsets, decides which default
platform should be used, and creates the required entities.
"""
if (
parameter in IGNORED_PARAMETERS
or parameter.endswith(tuple(IGNORED_PARAMETERS_WILDCARDS_END))
or parameter.startswith(tuple(IGNORED_PARAMETERS_WILDCARDS_START))
) and parameter not in WHITELIST_PARAMETERS:
if _ignore_parameter(
parameter=parameter, channel_no=get_device_channel(channel_address)
):
_LOGGER.debug(
"create_entity: Ignoring parameter: %s (%s)", parameter, channel_address
)
Expand Down Expand Up @@ -696,3 +695,20 @@ def _is_binary_sensor(parameter_data: dict[str, Any]) -> bool:
if value_list == ["CLOSED", "OPEN"]:
return True
return False


def _ignore_parameter(parameter: str, channel_no: int) -> bool:
"""Check if parameter can be ignored."""
if parameter in WHITELIST_PARAMETERS:
return False
if parameter in IGNORED_PARAMETERS:
return True
if parameter.endswith(tuple(IGNORED_PARAMETERS_WILDCARDS_END)):
return True
if parameter.startswith(tuple(IGNORED_PARAMETERS_WILDCARDS_START)):
return True
if (accept_channel := ACCEPT_PARAMETER_ONLY_ON_CHANNEL.get(parameter)) is not None:
if accept_channel != channel_no:
return True

return False
8 changes: 4 additions & 4 deletions hahomematic/devices/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ async def stop_cover(self) -> None:
await self._e_stop.send_value(True)

@property
def extra_state_attributes(self) -> dict[str, Any]:
def attributes(self) -> dict[str, Any]:
"""Return the state attributes of the cover."""
state_attr = super().extra_state_attributes
state_attr = super().attributes
if self._channel_level and self._channel_level != self._e_level.value:
state_attr[ATTR_CHANNEL_COVER_LEVEL] = self._channel_level * 100
return state_attr
Expand Down Expand Up @@ -176,9 +176,9 @@ async def stop_cover_tilt(self) -> None:
await self._e_stop.send_value(True)

@property
def extra_state_attributes(self) -> dict[str, Any]:
def attributes(self) -> dict[str, Any]:
"""Return the state attributes of the cover."""
state_attr = super().extra_state_attributes
state_attr = super().attributes
if self._channel_level_2 and self._channel_level_2 != self._e_level_2.value:
state_attr[ATTR_CHANNEL_TILT_LEVEL] = self._channel_level_2 * 100
return state_attr
Expand Down
8 changes: 4 additions & 4 deletions hahomematic/devices/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ async def turn_on(
await self._e_level.send_value(dim_level)

@property
def extra_state_attributes(self) -> dict[str, Any]:
def attributes(self) -> dict[str, Any]:
"""Return the state attributes of the light."""
state_attr = super().extra_state_attributes
state_attr = super().attributes
if (
self._channel_level
and self._e_level.value
Expand Down Expand Up @@ -279,9 +279,9 @@ async def turn_on(
await self._e_level.send_value(dim_level)

@property
def extra_state_attributes(self) -> dict[str, Any]:
def attributes(self) -> dict[str, Any]:
"""Return the state attributes of the notification light sensor."""
state_attr = super().extra_state_attributes
state_attr = super().attributes
if self.is_on:
state_attr[ATTR_COLOR_NAME] = self._e_color.value
if self._channel_level and self._channel_level != self._e_level.value:
Expand Down
4 changes: 2 additions & 2 deletions hahomematic/devices/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ async def turn_off(self) -> None:
await self._e_state.turn_off()

@property
def extra_state_attributes(self) -> dict[str, Any]:
def attributes(self) -> dict[str, Any]:
"""Return the state attributes of the switch."""
state_attr = super().extra_state_attributes
state_attr = super().attributes
if self._channel_state and self._channel_state != self._e_state.value:
state_attr[ATTR_CHANNEL_STATE] = self._channel_state
return state_attr
Expand Down
22 changes: 19 additions & 3 deletions hahomematic/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import hahomematic.client as hm_client
from hahomematic.const import (
ATTR_ADDRESS,
ATTR_ENTITY_TYPE,
ATTR_HM_DEFAULT,
ATTR_HM_FLAGS,
ATTR_HM_MAX,
Expand Down Expand Up @@ -43,6 +44,7 @@
TYPE_FLOAT,
TYPE_INTEGER,
TYPE_STRING,
HmEntityType,
HmEntityUsage,
HmEventType,
HmPlatform,
Expand Down Expand Up @@ -176,7 +178,7 @@ def device_info(self) -> dict[str, Any]:
return self._device.device_info

@property
def extra_state_attributes(self) -> dict[str, Any]:
def attributes(self) -> dict[str, Any]:
"""Return the state attributes of the base entity."""
return {
ATTR_INTERFACE_ID: self._interface_id,
Expand Down Expand Up @@ -262,9 +264,9 @@ def update_parameter_data(self) -> None:
self._assign_parameter_data()

@property
def extra_state_attributes(self) -> dict[str, Any]:
def attributes(self) -> dict[str, Any]:
"""Return the state attributes of the base entity."""
state_attr = super().extra_state_attributes
state_attr = super().attributes
state_attr[ATTR_PARAMETER] = self.parameter
return state_attr

Expand Down Expand Up @@ -425,6 +427,13 @@ def value(self) -> ParameterType | None:
"""Return the value of the entity."""
return self._value

@property
def attributes(self) -> dict[str, Any]:
"""Return the state attributes of the generic entity."""
state_attr = super().attributes
state_attr[ATTR_ENTITY_TYPE] = HmEntityType.GENERIC.value
return state_attr

async def load_data(self) -> int:
"""Load data"""
if self._updated_within_minutes():
Expand Down Expand Up @@ -514,6 +523,13 @@ def __init__(
self.data_entities: dict[str, GenericEntity] = {}
self._init_entities()

@property
def attributes(self) -> dict[str, Any]:
"""Return the state attributes of the custom entity."""
state_attr = super().attributes
state_attr[ATTR_ENTITY_TYPE] = HmEntityType.CUSTOM.value
return state_attr

def _custom_entity_usage(self) -> HmEntityUsage:
"""Return the custom entity usage."""
if secondary_channels := self._device_desc.get(
Expand Down
2 changes: 0 additions & 2 deletions hahomematic/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ async def _update_entities(self) -> None:
return

# remove some variables in case of CCU Backend
# - DutyCycle/CarrierSense are covered by real sensors
# - OldValue(s) are for internal calculations
# - Servicemeldungen are wrong in case of hmip (contains a dummy)
if self._central.model is BACKEND_CCU:
variables = _clean_variables(variables)

Expand Down
4 changes: 1 addition & 3 deletions tests/test_central.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ async def test_central(central, loop) -> None:
assert central
assert central.instance_name == "ccu-dev"
assert central.model == "PyDevCCU"
assert central.version == "pydevccu 0.0.9"
assert central.get_client_by_interface_id("ccu-dev-hm").model == "PyDevCCU"
assert central.get_client().model == "PyDevCCU"
assert len(central.hm_devices) == 338
assert len(central.hm_entities) == 3280
assert len(central.hm_entities) == 3242

data = {}
for device in central.hm_devices.values():
Expand Down Expand Up @@ -57,7 +56,6 @@ async def test_central(central, loop) -> None:
if entity.parameter not in parameters:
parameters.append(entity.parameter)


assert len(data) == 338
assert len(custom_entities) == 201
assert len(ce_channels) == 83
Expand Down

0 comments on commit 793810b

Please sign in to comment.