Skip to content

Commit

Permalink
Adjust payload and path
Browse files Browse the repository at this point in the history
  • Loading branch information
SukramJ committed Sep 12, 2024
1 parent 827403f commit 253952a
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 37 deletions.
6 changes: 6 additions & 0 deletions hahomematic/central/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from hahomematic.client.json_rpc import JsonRpcAioHttpClient
from hahomematic.client.xml_rpc import XmlRpcProxy
from hahomematic.const import (
APP_PATH,
CALLBACK_TYPE,
DATETIME_FORMAT_MILLIS,
DEFAULT_TLS,
Expand Down Expand Up @@ -263,6 +264,11 @@ def name(self) -> str:
"""Return the name of the backend."""
return self._config.name

@property
def path(self) -> str:
"""Return the base path of the entity."""
return f"{APP_PATH}/{self.name}"

@property
def program_buttons(self) -> tuple[HmProgramButton, ...]:
"""Return the program entities."""
Expand Down
10 changes: 6 additions & 4 deletions hahomematic/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,18 @@
ALLOWED_HOSTNAME_PATTERN: Final = re.compile(r"(?!-)[a-z0-9-]{1,63}(?<!-)$", re.IGNORECASE)
HTMLTAG_PATTERN: Final = re.compile(r"<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});")

IDENTIFIER_SEPARATOR: Final = "@"
APP_PATH: Final = "homematicip_local"
HUB_PATH: Final = "hub"
BLOCK_LOG_TIMEOUT = 60
CACHE_PATH: Final = "cache"
DATETIME_FORMAT: Final = "%d.%m.%Y %H:%M:%S"
DATETIME_FORMAT_MILLIS: Final = "%d.%m.%Y %H:%M:%S.%f'"
IDENTIFIER_SEPARATOR: Final = "@"
INIT_DATETIME: Final = datetime.strptime("01.01.1970 00:00:00", DATETIME_FORMAT)
IP_ANY_V4: Final = "0.0.0.0"
PORT_ANY: Final = 0
BLOCK_LOG_TIMEOUT = 60
CACHE_PATH: Final = "cache"
KWARGS_ARG_ENTITY = "entity"
PATH_JSON_RPC: Final = "/api/homematic.cgi"
PORT_ANY: Final = 0

HOMEGEAR_SERIAL = "Homegear_SN0815"

Expand Down
2 changes: 1 addition & 1 deletion hahomematic/platforms/custom/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def supports_hs_color(self) -> bool:
DeviceOperationMode.RGB,
)

@config_property
@property
def usage(self) -> EntityUsage:
"""
Return the entity usage.
Expand Down
17 changes: 11 additions & 6 deletions hahomematic/platforms/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ def available_firmware(self) -> str | None:
"""Return the available firmware of the device."""
return str(self._device_description.get("AVAILABLE_FIRMWARE", ""))

@property
def path(self) -> str:
"""Return the base path of the entity."""
return f"{self._central.path}/{self._device_address}"

@property
def central(self) -> hmcu.CentralUnit:
"""Return the central of the device."""
Expand Down Expand Up @@ -228,7 +233,7 @@ def has_custom_entity_definition(self) -> bool:
"""Return if custom_entity definition is available for the device."""
return self._has_custom_entity_definition

@config_property
@property
def has_sub_devices(self) -> bool:
"""Return if device has multiple sub device channels."""
return len(set(self._sub_device_channels.values())) > 1
Expand All @@ -248,12 +253,12 @@ def interface_id(self) -> str:
"""Return the interface_id of the device."""
return self._interface_id

@config_property
@property
def ignore_for_custom_entity(self) -> bool:
"""Return if device should be ignored for custom entity."""
return self._ignore_for_custom_entity

@config_property
@property
def is_updatable(self) -> bool:
"""Return if the device is updatable."""
return self._is_updatable
Expand All @@ -268,7 +273,7 @@ def name(self) -> str:
"""Return the name of the device."""
return self._name

@config_property
@property
def product_group(self) -> ProductGroup:
"""Return the product group of the device."""
return self._product_group
Expand All @@ -285,12 +290,12 @@ def rooms(self) -> set[str]:
"""Return all rooms of the device."""
return self._rooms

@config_property
@property
def rx_modes(self) -> tuple[RxMode, ...]:
"""Return the rx mode."""
return self._rx_modes

@config_property
@property
def sub_type(self) -> str | None:
"""Return the sub_type of the device."""
return self._sub_type
Expand Down
24 changes: 12 additions & 12 deletions hahomematic/platforms/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ def unique_id(self) -> str:
"""Return the unique_id."""
return self._unique_id

@config_property
@property
def usage(self) -> EntityUsage:
"""Return the entity usage."""
return EntityUsage.ENTITY

@config_property
@property
def enabled_default(self) -> bool:
"""Return, if entity should be enabled based on usage attribute."""
return self.usage in (
Expand Down Expand Up @@ -313,19 +313,19 @@ def base_channel_no(self) -> int | None:
@property
def _base_path(self) -> str:
"""Return the base path of the entity."""
return f"{self._central.name}/{self._device.device_address}/{self._channel_no}/{self._platform}"
return f"{self._device.path}/{self._channel_no}/{self._platform}"

@config_property
def channel_address(self) -> str:
"""Return the channel_address of the entity."""
return self._channel_address

@config_property
@property
def channel_no(self) -> int:
"""Return the channel_no of the entity."""
return self._channel_no

@config_property
@property
def channel_unique_id(self) -> str:
"""Return the channel_unique_id of the entity."""
return self._channel_unique_id
Expand All @@ -345,7 +345,7 @@ def full_name(self) -> str:
"""Return the full name of the entity."""
return self._entity_name_data.full_name

@config_property
@property
def is_in_multiple_channels(self) -> bool:
"""Return the parameter/CE is also in multiple channels."""
return self._is_in_multiple_channels
Expand All @@ -372,7 +372,7 @@ def rooms(self) -> set[str]:
"""Return the rooms assigned to an entity."""
return self._rooms

@config_property
@property
def usage(self) -> EntityUsage:
"""Return the entity usage."""
return self._get_entity_usage()
Expand Down Expand Up @@ -475,17 +475,17 @@ def hmtype(self) -> ParameterType:
"""Return the HomeMatic type."""
return self._type

@config_property
@property
def is_unit_fixed(self) -> bool:
"""Return if the unit is fixed."""
return self._raw_unit != self._unit

@config_property
@property
def is_un_ignored(self) -> bool:
"""Return if the parameter is un ignored."""
return self._is_un_ignored

@config_property
@property
def entity_key(self) -> ENTITY_KEY:
"""Return entity key value."""
return get_entity_key(
Expand All @@ -504,7 +504,7 @@ def min(self) -> ParameterT:
"""Return min value."""
return self._min

@config_property
@property
def multiplier(self) -> int:
"""Return multiplier value."""
return self._multiplier
Expand All @@ -524,7 +524,7 @@ def path(self) -> str:
"""Return the path of the entity."""
return f"{self._base_path}/{self._parameter}".lower()

@config_property
@property
def raw_unit(self) -> str | None:
"""Return raw unit value."""
return self._raw_unit
Expand Down
2 changes: 1 addition & 1 deletion hahomematic/platforms/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(
parameter_data=parameter_data,
)

@config_property
@property
def usage(self) -> EntityUsage:
"""Return the entity usage."""
if (forced_by_com := self._enabled_by_channel_operation_mode) is None:
Expand Down
3 changes: 1 addition & 2 deletions hahomematic/platforms/generic/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
ParamsetKey,
)
from hahomematic.platforms import device as hmd, entity as hme
from hahomematic.platforms.decorators import config_property
from hahomematic.platforms.support import EntityNameData, GenericParameterType, get_entity_name

_LOGGER: Final = logging.getLogger(__name__)
Expand Down Expand Up @@ -47,7 +46,7 @@ def __init__(
parameter_data=parameter_data,
)

@config_property
@property
def usage(self) -> EntityUsage:
"""Return the entity usage."""
if self._is_forced_sensor or self._is_un_ignored:
Expand Down
6 changes: 3 additions & 3 deletions hahomematic/platforms/hub/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from slugify import slugify

from hahomematic import central as hmcu
from hahomematic.const import SYSVAR_ADDRESS, HubData, SystemVariableData
from hahomematic.const import HUB_PATH, SYSVAR_ADDRESS, HubData, SystemVariableData
from hahomematic.platforms.decorators import config_property, state_property
from hahomematic.platforms.entity import CallbackEntity
from hahomematic.platforms.support import generate_unique_id
Expand All @@ -32,7 +32,7 @@ def __init__(
)
super().__init__(central=central, unique_id=unique_id)
self._name: Final = self.get_name(data=data)
self._full_name: Final = f"{self.central.name}_{self._name}"
self._full_name: Final = f"{self._central.name}_{self._name}"

@abstractmethod
def get_name(self, data: HubData) -> str:
Expand All @@ -51,7 +51,7 @@ def name(self) -> str | None:
@property
def path(self) -> str:
"""Return the path of the entity."""
return f"{self.central.name}/{self.platform}".lower()
return f"{self._central.name}/{HUB_PATH}/{self.platform}/{self.name}".lower()


class GenericSystemVariable(GenericHubEntity):
Expand Down
4 changes: 2 additions & 2 deletions hahomematic/platforms/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def payload_config(self) -> Mapping[str, Any]:
return get_public_attributes_for_config_property(data_object=self)

@property
def payload_value(self) -> Mapping[str, Any]:
"""Return the payload value."""
def payload_state(self) -> Mapping[str, Any]:
"""Return the payload state."""
return get_public_attributes_for_state_property(data_object=self)


Expand Down
2 changes: 1 addition & 1 deletion hahomematic/platforms/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def latest_firmware(self) -> str | None:
@property
def path(self) -> str:
"""Return the path of the entity."""
return f"{self._central.name}/{self._device.device_address}/{HmPlatform.UPDATE}".lower()
return f"{self._device.path}/{HmPlatform.UPDATE}".lower()

def register_entity_updated_callback(self, cb: Callable, custom_id: str) -> CALLBACK_TYPE:
"""Register update callback."""
Expand Down
3 changes: 1 addition & 2 deletions tests/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

from hahomematic.platforms.decorators import (
config_property,
get_public_attributes_for_config_property,
get_public_attributes_for_state_property,
state_property,
Expand Down Expand Up @@ -59,7 +58,7 @@ def value(self) -> None:
"""Delete value."""
self._value = ""

@config_property
@property
def config(self) -> str:
"""Return config."""
return self._config
Expand Down
9 changes: 6 additions & 3 deletions tests/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from hahomematic.caches.visibility import check_ignore_parameters_is_clean
from hahomematic.central import CentralUnit
from hahomematic.client import Client
from hahomematic.const import CallSource, EntityUsage
from hahomematic.const import APP_PATH, CallSource, EntityUsage
from hahomematic.platforms.custom.definition import (
get_required_parameters,
validate_entity_definition,
Expand Down Expand Up @@ -66,7 +66,10 @@ async def test_custom_entity_callback(
cb=device_removed_mock
)
assert switch.value is None
assert str(switch) == "path: centraltest/vcu2128127/4/switch, name: HmIP-BSM_VCU2128127"
assert (
str(switch)
== f"path: {APP_PATH}/centraltest/vcu2128127/4/switch, name: HmIP-BSM_VCU2128127"
)
await central.event(const.INTERFACE_ID, "VCU2128127:4", "STATE", 1)
assert switch.value is True
await central.event(const.INTERFACE_ID, "VCU2128127:4", "STATE", 0)
Expand Down Expand Up @@ -114,7 +117,7 @@ async def test_generic_entity_callback(
assert switch.value is None
assert (
str(switch)
== "path: centraltest/vcu2128127/4/switch/state, name: HmIP-BSM_VCU2128127 State ch4"
== f"path: {APP_PATH}/centraltest/vcu2128127/4/switch/state, name: HmIP-BSM_VCU2128127 State ch4"
)
await central.event(const.INTERFACE_ID, "VCU2128127:4", "STATE", 1)
assert switch.value is True
Expand Down

0 comments on commit 253952a

Please sign in to comment.