diff --git a/hahomematic/central/__init__.py b/hahomematic/central/__init__.py index ca5e1be2..47c91c98 100644 --- a/hahomematic/central/__init__.py +++ b/hahomematic/central/__init__.py @@ -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, @@ -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.""" diff --git a/hahomematic/const.py b/hahomematic/const.py index a6f6a88e..4da32405 100644 --- a/hahomematic/const.py +++ b/hahomematic/const.py @@ -42,16 +42,18 @@ ALLOWED_HOSTNAME_PATTERN: Final = re.compile(r"(?!-)[a-z0-9-]{1,63}(?|&([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" diff --git a/hahomematic/platforms/custom/light.py b/hahomematic/platforms/custom/light.py index c05594ad..8044ef54 100644 --- a/hahomematic/platforms/custom/light.py +++ b/hahomematic/platforms/custom/light.py @@ -509,7 +509,7 @@ def supports_hs_color(self) -> bool: DeviceOperationMode.RGB, ) - @config_property + @property def usage(self) -> EntityUsage: """ Return the entity usage. diff --git a/hahomematic/platforms/device.py b/hahomematic/platforms/device.py index 53492ff0..b78523f5 100644 --- a/hahomematic/platforms/device.py +++ b/hahomematic/platforms/device.py @@ -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.""" @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/hahomematic/platforms/entity.py b/hahomematic/platforms/entity.py index 34232ac9..06f9ec8d 100644 --- a/hahomematic/platforms/entity.py +++ b/hahomematic/platforms/entity.py @@ -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 ( @@ -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 @@ -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 @@ -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() @@ -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( @@ -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 @@ -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 diff --git a/hahomematic/platforms/event.py b/hahomematic/platforms/event.py index 6acaef2b..347aebf0 100644 --- a/hahomematic/platforms/event.py +++ b/hahomematic/platforms/event.py @@ -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: diff --git a/hahomematic/platforms/generic/entity.py b/hahomematic/platforms/generic/entity.py index 66f5fcf3..f6b60abd 100644 --- a/hahomematic/platforms/generic/entity.py +++ b/hahomematic/platforms/generic/entity.py @@ -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__) @@ -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: diff --git a/hahomematic/platforms/hub/entity.py b/hahomematic/platforms/hub/entity.py index 539b0412..684faacf 100644 --- a/hahomematic/platforms/hub/entity.py +++ b/hahomematic/platforms/hub/entity.py @@ -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 @@ -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: @@ -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): diff --git a/hahomematic/platforms/support.py b/hahomematic/platforms/support.py index b9fa4e3b..0e484123 100644 --- a/hahomematic/platforms/support.py +++ b/hahomematic/platforms/support.py @@ -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) diff --git a/hahomematic/platforms/update.py b/hahomematic/platforms/update.py index 95765091..927c5862 100644 --- a/hahomematic/platforms/update.py +++ b/hahomematic/platforms/update.py @@ -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.""" diff --git a/tests/test_decorator.py b/tests/test_decorator.py index 3af9ae83..68f92ce2 100644 --- a/tests/test_decorator.py +++ b/tests/test_decorator.py @@ -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, @@ -59,7 +58,7 @@ def value(self) -> None: """Delete value.""" self._value = "" - @config_property + @property def config(self) -> str: """Return config.""" return self._config diff --git a/tests/test_entity.py b/tests/test_entity.py index 7e8f342f..e938206f 100644 --- a/tests/test_entity.py +++ b/tests/test_entity.py @@ -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, @@ -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) @@ -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