diff --git a/changelog.txt b/changelog.txt index e28bf262..7ccd850e 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,7 @@ +Version 0.16.0 (2022-01-08) +- Return unique_id if name is not in cache +- Remove no longer needed press_virtual_remote_key + Version 0.15.2 (2022-01-07) - Add devices to CustomEntity - HmIP-WGC diff --git a/hahomematic/central_unit.py b/hahomematic/central_unit.py index 81922086..865d942f 100644 --- a/hahomematic/central_unit.py +++ b/hahomematic/central_unit.py @@ -267,7 +267,7 @@ async def delete_devices(self, interface_id: str, addresses: list[str]) -> None: async def add_new_devices( self, interface_id: str, dev_descriptions: list[dict[str, Any]] ) -> None: - """Async implementation""" + """Add new devices to central unit.""" _LOGGER.debug( "CentralUnit.add_new_devices: interface_id = %s, dev_descriptions = %s", interface_id, @@ -276,7 +276,7 @@ async def add_new_devices( if interface_id not in self.clients: _LOGGER.error( - "RPCFunctions.newDevices: Missing client for interface_id %s.", + "CentralUnit.add_new_devices: Missing client for interface_id %s.", interface_id, ) return None @@ -293,7 +293,7 @@ async def add_new_devices( self.raw_devices.add_device_description(interface_id, dev_desc) await client.fetch_paramsets(dev_desc) except Exception: - _LOGGER.exception("RPCFunctions.newDevices: Exception") + _LOGGER.exception("CentralUnit.add_new_devices: Exception") await self.raw_devices.save() await self.paramsets.save() await client.fetch_names() @@ -475,32 +475,6 @@ def _get_virtual_remote(self, device_address: str) -> HmDevice | None: return virtual_remote return None - async def press_virtual_remote_key( - self, channel_address: str, parameter: str - ) -> None: - """Simulate a key press on the virtual remote.""" - if ":" not in channel_address: - _LOGGER.warning( - "CentralUnit.press_virtual_remote_key: channel_address is missing channel information." - ) - - if channel_address.startswith(HM_VIRTUAL_REMOTE_HM.upper()): - channel_address = channel_address.replace( - HM_VIRTUAL_REMOTE_HM.upper(), HM_VIRTUAL_REMOTE_HM - ) - if channel_address.startswith(HM_VIRTUAL_REMOTE_HMIP.upper()): - channel_address = channel_address.replace( - HM_VIRTUAL_REMOTE_HMIP.upper(), HM_VIRTUAL_REMOTE_HMIP - ) - - if virtual_remote := self._get_virtual_remote( - get_device_address(channel_address) - ): - if virtual_remote_channel := virtual_remote.action_events.get( - (channel_address, parameter) - ): - await virtual_remote_channel.send_value(True) - def get_hm_entities_by_hmplatform(self, platform: HmPlatform) -> list[BaseEntity]: """ Return all hm-entities by platform diff --git a/hahomematic/devices/entity_definition.py b/hahomematic/devices/entity_definition.py index 9c4112b8..faa4f492 100644 --- a/hahomematic/devices/entity_definition.py +++ b/hahomematic/devices/entity_definition.py @@ -336,7 +336,6 @@ def __str__(self) -> str: 1: { FIELD_HUMIDITY: "ACTUAL_HUMIDITY", FIELD_TEMPERATURE: "ACTUAL_TEMPERATURE", - FIELD_LEVEL: "VALVE_STATE", } }, }, diff --git a/hahomematic/helpers.py b/hahomematic/helpers.py index e0402a22..8390b98b 100644 --- a/hahomematic/helpers.py +++ b/hahomematic/helpers.py @@ -119,28 +119,28 @@ def get_entity_name( device_type: str, ) -> str: """generate name for entity""" - entity_name = _get_base_name_from_channel_or_device( + if entity_name := _get_base_name_from_channel_or_device( central=central, channel_address=channel_address, - unique_id=unique_id, device_type=device_type, - ) - - if entity_name.count(":") == 1: - d_name = entity_name.split(":")[0] - p_name = parameter.title().replace("_", " ") - c_name = "" - if central.paramsets.has_multiple_channels( - channel_address=channel_address, parameter=parameter - ): - c_no = entity_name.split(":")[1] - c_name = "" if c_no == "0" else f" ch{c_no}" - entity_name = f"{d_name} {p_name}{c_name}" - else: - d_name = entity_name - p_name = parameter.title().replace("_", " ") - entity_name = f"{d_name} {p_name}" - return entity_name + ): + if entity_name.count(":") == 1: + d_name = entity_name.split(":")[0] + p_name = parameter.title().replace("_", " ") + c_name = "" + if central.paramsets.has_multiple_channels( + channel_address=channel_address, parameter=parameter + ): + c_no = entity_name.split(":")[1] + c_name = "" if c_no == "0" else f" ch{c_no}" + entity_name = f"{d_name} {p_name}{c_name}" + else: + d_name = entity_name + p_name = parameter.title().replace("_", " ") + entity_name = f"{d_name} {p_name}" + return entity_name + + return unique_id def get_event_name( @@ -151,23 +151,24 @@ def get_event_name( device_type: str, ) -> str: """generate name for event""" - event_name = _get_base_name_from_channel_or_device( + if event_name := _get_base_name_from_channel_or_device( central=central, channel_address=channel_address, - unique_id=unique_id, device_type=device_type, - ) - if event_name.count(":") == 1: - d_name = event_name.split(":")[0] - p_name = parameter.title().replace("_", " ") - c_no = event_name.split(":")[1] - c_name = "" if c_no == "0" else f" Channel {c_no}" - event_name = f"{d_name}{c_name} {p_name}" - else: - d_name = event_name - p_name = parameter.title().replace("_", " ") - event_name = f"{d_name} {p_name}" - return event_name + ): + if event_name.count(":") == 1: + d_name = event_name.split(":")[0] + p_name = parameter.title().replace("_", " ") + c_no = event_name.split(":")[1] + c_name = "" if c_no == "0" else f" Channel {c_no}" + event_name = f"{d_name}{c_name} {p_name}" + else: + d_name = event_name + p_name = parameter.title().replace("_", " ") + event_name = f"{d_name} {p_name}" + return event_name + + return unique_id def get_custom_entity_name( @@ -179,16 +180,16 @@ def get_custom_entity_name( is_only_primary_channel: bool, ) -> str: """Rename name for custom entity""" - custom_entity_name = _get_base_name_from_channel_or_device( + if custom_entity_name := _get_base_name_from_channel_or_device( central=central, channel_address=f"{device_address}:{channel_no}", - unique_id=unique_id, device_type=device_type, - ) - if is_only_primary_channel and ":" in custom_entity_name: - return custom_entity_name.split(":")[0] + ): + if is_only_primary_channel and ":" in custom_entity_name: + return custom_entity_name.split(":")[0] + return custom_entity_name.replace(":", " ch") - return custom_entity_name.replace(":", " ch") + return unique_id def check_channel_is_only_primary_channel( @@ -205,9 +206,8 @@ def check_channel_is_only_primary_channel( def _get_base_name_from_channel_or_device( central: hm_central.CentralUnit, channel_address: str, - unique_id: str, device_type: str, -) -> str: +) -> str | None: """Get the name from channel if it's not default, otherwise from device.""" default_channel_name = f"{device_type} {channel_address}" name = central.names.get_name(channel_address) @@ -215,9 +215,6 @@ def _get_base_name_from_channel_or_device( channel_no = get_device_channel(channel_address) if device_name := central.names.get_name(get_device_address(channel_address)): name = f"{device_name}:{channel_no}" - if name is None: - name = unique_id - return name diff --git a/setup.py b/setup.py index a2fa1907..0f8d203d 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ def readme(): }, PACKAGE_NAME = "hahomematic" HERE = os.path.abspath(os.path.dirname(__file__)) -VERSION = "0.15.2" +VERSION = "0.16.0" PACKAGES = find_packages(exclude=["tests", "tests.*", "dist", "build"])