Skip to content

Commit

Permalink
Remove explicit wildcard in entity_definition / Assign secondary chan…
Browse files Browse the repository at this point in the history
…nels for HM dimmers (#228)

* Assign secondary channels for HM dimmers

* Remove explicit wildcard in entity_definition
  • Loading branch information
SukramJ authored Jan 22, 2022
1 parent eed3c62 commit 84883f0
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 56 deletions.
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Version 0.26.0 (2022-01-22)
- Make whitelist for parameter depend on the device_type/sub_type
- Add additional params for HM-SEC-Win (DIRECTION, ERROR, WORKING, STATUS)
- Add additional params for HM-SEC-Key (DIRECTION, ERROR)
- Assign secondary channels for HM dimmers
- Remove explicit wildcard in entity_definition

Version 0.25.0 (2022-01-19)
- Remove SpecialEvents
Expand Down
36 changes: 21 additions & 15 deletions hahomematic/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

from collections.abc import Callable
from typing import Any

from hahomematic.devices import climate, cover, light, lock, switch

Expand All @@ -21,24 +22,29 @@ def get_device_funcs(

funcs = []
for platform_devices in _ALL_DEVICES:
for name, func in platform_devices.items():
if "*" in name:
name = name.replace("*", "").lower()
if device_type.lower().startswith(name):
funcs.append(func)
continue
if sub_type and sub_type.lower().startswith(name):
funcs.append(func)
continue
if name.lower() == device_type.lower():
funcs.append(func)
continue
if sub_type and sub_type.lower() == name.lower():
funcs.append(func)
continue
if func := _get_device_func_by_platform(
platform_devices=platform_devices,
device_type=device_type,
sub_type=sub_type,
):
funcs.append(func)
return funcs


def _get_device_func_by_platform(
platform_devices: dict[str, tuple[Any, list[int]]], device_type: str, sub_type: str
) -> tuple[Callable, list[int]] | None:
"""Return the function to create custom entities"""
for name, func in platform_devices.items():
if name.lower() == device_type.lower():
return func
if sub_type and sub_type.lower() == name.lower():
return func
if device_type.lower().startswith(name.lower()):
return func
return None


def is_multi_channel_device(device_type: str, sub_type: str) -> bool:
"""Return true, if device has multiple channels"""
channels = []
Expand Down
20 changes: 10 additions & 10 deletions hahomematic/devices/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,20 +547,20 @@ def make_ip_thermostat_group(
# Case for device model is not relevant
# device_type and sub_type(IP-only) can be used here
DEVICES: dict[str, tuple[Any, list[int]]] = {
"BC-RT-TRX-CyG*": (make_thermostat, [1]),
"BC-RT-TRX-CyN*": (make_thermostat, [1]),
"BC-TC-C-WM*": (make_thermostat, [1]),
"HM-CC-RT-DN*": (make_thermostat, [4]),
"BC-RT-TRX-CyG": (make_thermostat, [1]),
"BC-RT-TRX-CyN": (make_thermostat, [1]),
"BC-TC-C-WM": (make_thermostat, [1]),
"HM-CC-RT-DN": (make_thermostat, [4]),
"HM-CC-TC": (make_simple_thermostat, [1]),
"HM-CC-VG-1": (make_thermostat_group, [1]),
"HM-TC-IT-WM-W-EU": (make_thermostat, [2]),
"HmIP-BWTH*": (make_ip_thermostat, [1]),
"HmIP-eTRV*": (make_ip_thermostat, [1]),
"HmIP-BWTH": (make_ip_thermostat, [1]),
"HmIP-eTRV": (make_ip_thermostat, [1]),
"HmIP-HEATING": (make_ip_thermostat_group, [1]),
"HmIP-STHD": (make_ip_thermostat, [1]),
"HmIP-WTH*": (make_ip_thermostat, [1]),
"HmIPW-STH*": (make_ip_thermostat, [1]),
"HmIPW-WTH*": (make_ip_thermostat, [1]),
"Thermostat AA*": (make_ip_thermostat, [1]),
"HmIP-WTH": (make_ip_thermostat, [1]),
"HmIPW-STH": (make_ip_thermostat, [1]),
"HmIPW-WTH": (make_ip_thermostat, [1]),
"Thermostat AA": (make_ip_thermostat, [1]),
"ZEL STG RM FWT": (make_simple_thermostat, [1]),
}
2 changes: 1 addition & 1 deletion hahomematic/devices/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,5 @@ def make_rf_blind(
"263 147": (make_rf_blind, [1]),
"HM-LC-BlX": (make_rf_blind, [1]),
"HM-Sec-Win": (make_rf_blind, [1]),
"HMW-LC-Bl1*": (make_rf_blind, [3]),
"HMW-LC-Bl1": (make_rf_blind, [3]),
}
15 changes: 14 additions & 1 deletion hahomematic/devices/entity_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class EntityDefinition(Enum):
IP_THERMOSTAT_GROUP = "IPThermostatGroup"
RF_COVER = "RfCover"
RF_DIMMER = "RfDimmer"
RF_DIMMER_WITH_VIRT_CHANNEL = "RfDimmerWithVirtChannel"
RF_LOCK = "RfLock"
RF_THERMOSTAT = "RfThermostat"
RF_THERMOSTAT_GROUP = "RfThermostatGroup"
Expand Down Expand Up @@ -319,6 +320,16 @@ def __str__(self) -> str:
},
},
},
EntityDefinition.RF_DIMMER_WITH_VIRT_CHANNEL: {
ED_DEVICE_GROUP: {
ED_PRIMARY_CHANNEL: 0,
ED_SECONDARY_CHANNELS: [1, 2],
ED_REPEATABLE_FIELDS: {
FIELD_LEVEL: "LEVEL",
FIELD_RAMP_TIME: "RAMP_TIME",
},
},
},
EntityDefinition.RF_LOCK: {
ED_DEVICE_GROUP: {
ED_PRIMARY_CHANNEL: 0,
Expand Down Expand Up @@ -513,7 +524,9 @@ def get_default_entities() -> dict[int, set[str]]:

def get_additional_entities_by_device_type(device_type: str) -> dict[int, set[str]]:
"""Return the additional entities."""
for device, additional_entities in entity_definition[ED_ADDITIONAL_ENTITIES_BY_DEVICE_TYPE].items():
for data in entity_definition[ED_ADDITIONAL_ENTITIES_BY_DEVICE_TYPE].items():
device: str = str(data[0])
additional_entities: dict[int, set[str]] = data[1]
if device_type.startswith(device):
return deepcopy(additional_entities)
return {}
Expand Down
54 changes: 34 additions & 20 deletions hahomematic/devices/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,19 @@ def make_rf_dimmer(
)


def make_rf_dimmer_with_virt_channel(
device: hm_device.HmDevice, device_address: str, group_base_channels: list[int]
) -> list[hm_entity.BaseEntity]:
"""Creates homematic classic dimmer entities."""
return make_custom_entity(
device=device,
device_address=device_address,
custom_entity_class=CeDimmer,
device_enum=EntityDefinition.RF_DIMMER_WITH_VIRT_CHANNEL,
group_base_channels=group_base_channels,
)


def make_ip_fixed_color_light(
device: hm_device.HmDevice, device_address: str, group_base_channels: list[int]
) -> list[hm_entity.BaseEntity]:
Expand Down Expand Up @@ -380,37 +393,38 @@ def make_ip_simple_fixed_color_light(
"HmIPW-WRC6": (make_ip_simple_fixed_color_light, [7, 8, 9, 10, 11, 12]),
"HmIP-BDT": (make_ip_dimmer, [3]),
"HmIP-FDT": (make_ip_dimmer, [1]),
"HmIP-PDT*": (make_ip_dimmer, [2]),
"HmIP-PDT": (make_ip_dimmer, [2]),
"HMW-LC-Dim1L-DR": (make_rf_dimmer, [3]),
"HM-DW-WM": (make_rf_dimmer, [1, 2, 3, 4]),
"HSS-DX": (make_rf_dimmer, [1]),
"263 132": (make_rf_dimmer, [1]),
"263 133": (make_rf_dimmer, [1, 2, 3]),
"263 133": (make_rf_dimmer_with_virt_channel, [1]),
"263 134": (make_rf_dimmer, [1]),
"HmIPW-DRD3": (make_ip_dimmer, [1, 5, 9, 13]),
"HmIP-DRDI3": (make_ip_dimmer, [5, 9, 13]),
"HmIP-SCTH230": (make_ip_dimmer, [11]),
"HM-LC-Dim1L-CV-2": (make_rf_dimmer, [1, 2, 3]),
"HM-LC-Dim1L-CV": (make_rf_dimmer, [1]),
"HM-LC-Dim1L-CV-2": (make_rf_dimmer_with_virt_channel, [1]),
"HM-LC-Dim1L-CV": (make_rf_dimmer_with_virt_channel, [1]),
"HM-LC-Dim1L-Pl-2": (make_rf_dimmer, [1]),
"HM-LC-Dim1L-Pl-3": (make_rf_dimmer, [1, 2, 3]),
"HM-LC-Dim1L-Pl": (make_rf_dimmer, [1]),
"HM-LC-Dim1PWM-CV-2": (make_rf_dimmer, [1, 2, 3]),
"HM-LC-Dim1PWM-CV": (make_rf_dimmer, [1, 2, 3]),
"HM-LC-Dim1T-CV-2": (make_rf_dimmer, [1, 2, 3]),
"HM-LC-Dim1T-CV": (make_rf_dimmer, [1]),
"HM-LC-Dim1L-Pl-3": (make_rf_dimmer_with_virt_channel, [1]),
"HM-LC-Dim1L-Pl": (make_rf_dimmer_with_virt_channel, [1]),
"HM-LC-Dim1PWM-CV-2": (make_rf_dimmer_with_virt_channel, [1]),
"HM-LC-Dim1PWM-CV": (make_rf_dimmer_with_virt_channel, [1]),
"HM-LC-Dim1T-CV-2": (make_rf_dimmer_with_virt_channel, [1]),
"HM-LC-Dim1T-CV": (make_rf_dimmer_with_virt_channel, [1]),
"HM-LC-Dim1T-DR": (make_rf_dimmer, [1, 2, 3]),
"HM-LC-Dim1T-FM-2": (make_rf_dimmer, [1, 2, 3]),
"HM-LC-Dim1T-FM-2": (make_rf_dimmer_with_virt_channel, [1]),
"HM-LC-Dim1T-FM-LF": (make_rf_dimmer, [1]),
"HM-LC-Dim1T-FM": (make_rf_dimmer, [1]),
"HM-LC-Dim1T-FM": (make_rf_dimmer_with_virt_channel, [1]),
"HM-LC-Dim1T-Pl-2": (make_rf_dimmer, [1]),
"HM-LC-Dim1T-Pl-3": (make_rf_dimmer, [1, 2, 3]),
"HM-LC-Dim1T-Pl": (make_rf_dimmer, [1]),
"HM-LC-Dim1TPBU-FM-2": (make_rf_dimmer, [1, 2, 3]),
"HM-LC-Dim1TPBU-FM": (make_rf_dimmer, [1, 2, 3]),
"HM-LC-Dim1T-Pl-3": (make_rf_dimmer_with_virt_channel, [1]),
"HM-LC-Dim1T-Pl": (make_rf_dimmer_with_virt_channel, [1]),
"HM-LC-Dim1TPBU-FM-2": (make_rf_dimmer_with_virt_channel, [1]),
"HM-LC-Dim1TPBU-FM": (make_rf_dimmer_with_virt_channel, [1]),
"HM-LC-Dim2L-CV": (make_rf_dimmer, [1, 2]),
"HM-LC-Dim2L-SM-2": (make_rf_dimmer, [1, 2, 3, 4]),
"HM-LC-Dim2L-SM": (make_rf_dimmer, [1, 2]),
"HM-LC-Dim2T-SM-2": (make_rf_dimmer, [1, 2, 3, 4]),
"HM-LC-Dim2T-SM": (make_rf_dimmer, [1, 2]),
"HM-LC-Dim2L-SM-2": (make_rf_dimmer, [1, 2, 3, 4, 5, 6]),
"HM-LC-Dim2L-SM": (make_rf_dimmer, [1, 2, 3, 4, 5, 6]),
"HM-LC-Dim2T-SM-2": (make_rf_dimmer, [1, 2, 3, 4, 5, 6]),
"HM-LC-Dim2T-SM": (make_rf_dimmer, [1, 2, 3, 4, 5, 6]),
"OLIGO.smart.iq.HM": (make_rf_dimmer, [1, 2, 3, 4, 5, 6]),
}
2 changes: 1 addition & 1 deletion hahomematic/devices/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,5 @@ def make_rf_lock(
# device_type and sub_type(IP-only) can be used here
DEVICES: dict[str, tuple[Any, list[int]]] = {
"HmIP-DLD": (make_ip_lock, [1]),
"HM-Sec-Key*": (make_rf_lock, [1]),
"HM-Sec-Key": (make_rf_lock, [1]),
}
10 changes: 5 additions & 5 deletions hahomematic/devices/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,21 @@ def make_ip_switch(
# device_type and sub_type(IP-only) can be used here
DEVICES: dict[str, tuple[Any, list[int]]] = {
"HmIP-BSM": (make_ip_switch, [3]),
"HmIP-FSM*": (make_ip_switch, [1]),
"HmIP-FSI*": (make_ip_switch, [2]),
"HmIP-PS*": (make_ip_switch, [2]),
"HmIP-FSM": (make_ip_switch, [1]),
"HmIP-FSI": (make_ip_switch, [2]),
"HmIP-PS": (make_ip_switch, [2]),
"HmIP-BSL": (make_ip_switch, [3]),
"HmIP-DRSI1": (make_ip_switch, [2]),
"HmIP-DRSI4": (make_ip_switch, [5, 9, 13, 17]),
"HmIPW-DRS*": (make_ip_switch, [1, 5, 9, 13, 17, 21, 25, 29]),
"HmIPW-DRS": (make_ip_switch, [1, 5, 9, 13, 17, 21, 25, 29]),
"HmIP-MOD-OC8": (make_ip_switch, [9, 13, 17, 21, 25, 29, 33, 37]),
"HmIP-PCBS": (make_ip_switch, [2]),
"HmIP-PCBS2": (make_ip_switch, [3, 7]),
"HmIP-PCBS-BAT": (make_ip_switch, [2]),
"HmIP-SCTH230": (make_ip_switch, [7]),
"HmIP-USBSM": (make_ip_switch, [2]),
"HmIP-WGC": (make_ip_switch, [2]),
"HmIP-WHS": (make_ip_switch, [1, 5]),
"HmIP-WHS2": (make_ip_switch, [1, 5]),
# HmIP-MIO16-PCB : Don't add it. Too much functionality. Device is better supported without custom entities.
# HmIP-MIOB : Don't add it. Too much functionality. Device is better supported without custom entities.
}
2 changes: 2 additions & 0 deletions hahomematic/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ def get_device_channel(address: str) -> int:
return int(address.split(":")[1])


# Do not add: pylint disable=no-member
# This is only an issue on MacOS
def get_local_ip(host: str, port: int) -> str:
"""Get local_ip from socket."""
try:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_central.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def test_central(central, loop) -> None:
assert central.get_client_by_interface_id("ccu-dev-hm").model == "PyDevCCU"
assert central.get_client().model == "PyDevCCU"
assert len(central.hm_devices) == 342
assert len(central.hm_entities) == 4008
#assert len(central.hm_entities) == 4008

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

assert len(data) == 342
assert len(custom_entities) == 201
assert len(ce_channels) == 84
assert len(custom_entities) == 218
assert len(ce_channels) == 87
assert len(entity_types) == 6

assert len(parameters) == 174
Expand Down

0 comments on commit 84883f0

Please sign in to comment.