From 6be6412635dab6ec4e5b79f7640f532076a4fe70 Mon Sep 17 00:00:00 2001 From: Christian Stangier Date: Tue, 30 Jul 2024 20:36:28 +0200 Subject: [PATCH 1/5] Extract device_info to area --- custom_components/auto_areas/auto_area.py | 15 +++++++++++++++ custom_components/auto_areas/auto_entity.py | 10 ++-------- .../auto_areas/binary_sensors/presence.py | 3 ++- custom_components/auto_areas/cover.py | 8 +------- .../auto_areas/switches/presence_lock.py | 8 +------- .../auto_areas/switches/sleep_mode.py | 8 +------- 6 files changed, 22 insertions(+), 30 deletions(-) diff --git a/custom_components/auto_areas/auto_area.py b/custom_components/auto_areas/auto_area.py index 819aa48..34da45f 100644 --- a/custom_components/auto_areas/auto_area.py +++ b/custom_components/auto_areas/auto_area.py @@ -1,9 +1,11 @@ """Core area functionality.""" from __future__ import annotations +from token import NAME from homeassistant.core import HomeAssistant from homeassistant.helpers.area_registry import async_get as async_get_area_registry from homeassistant.helpers.device_registry import async_get as async_get_device_registry from homeassistant.helpers.entity_registry import async_get as async_get_entity_registry +from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.issue_registry import async_create_issue, IssueSeverity from homeassistant.config_entries import ConfigEntry from homeassistant.util import slugify @@ -20,6 +22,8 @@ ISSUE_TYPE_INVALID_AREA, LOGGER, RELEVANT_DOMAINS, + NAME, + VERSION ) @@ -102,6 +106,17 @@ def get_area_entity_ids(self, device_classes: list[str]) -> list[str]: or entity.original_device_class in device_classes ] + @property + def device_info(self) -> DeviceInfo: + """Information about this device.""" + return { + "identifiers": {(DOMAIN, self.config_entry.entry_id)}, + "name": NAME, + "model": VERSION, + "manufacturer": NAME, + "suggested_area": self.area_name, + } + @property def area_name(self) -> str: """Return area name or fallback.""" diff --git a/custom_components/auto_areas/auto_entity.py b/custom_components/auto_areas/auto_entity.py index 5c98f70..3dda360 100644 --- a/custom_components/auto_areas/auto_entity.py +++ b/custom_components/auto_areas/auto_entity.py @@ -16,7 +16,7 @@ from custom_components.auto_areas.calculations import get_calculation from .auto_area import AutoArea -from .const import DOMAIN, LOGGER, NAME, VERSION +from .const import LOGGER _TEntity = TypeVar("_TEntity", bound=Entity) _TDeviceClass = TypeVar( @@ -83,13 +83,7 @@ def device_class(self) -> _TDeviceClass: @cached_property def device_info(self) -> DeviceInfo: """Information about this device.""" - return { - "identifiers": {(DOMAIN, self.auto_area.config_entry.entry_id)}, - "name": NAME, - "model": VERSION, - "manufacturer": NAME, - "suggested_area": self.auto_area.area_name, - } + return self.auto_area.device_info @cached_property def suggested_display_precision(self) -> int | None: diff --git a/custom_components/auto_areas/binary_sensors/presence.py b/custom_components/auto_areas/binary_sensors/presence.py index 7fe894b..6d46ec9 100644 --- a/custom_components/auto_areas/binary_sensors/presence.py +++ b/custom_components/auto_areas/binary_sensors/presence.py @@ -1,7 +1,6 @@ """Presence binary sensor.""" from __future__ import annotations -from custom_components.auto_areas.ha_helpers import all_states_are_off from functools import cached_property from typing import Literal, override @@ -12,6 +11,8 @@ BinarySensorEntity, ) from homeassistant.helpers.event import async_track_state_change_event + +from custom_components.auto_areas.ha_helpers import all_states_are_off from custom_components.auto_areas.auto_area import AutoArea from custom_components.auto_areas.auto_entity import AutoEntity from custom_components.auto_areas.const import ( diff --git a/custom_components/auto_areas/cover.py b/custom_components/auto_areas/cover.py index 58d896d..a4354df 100644 --- a/custom_components/auto_areas/cover.py +++ b/custom_components/auto_areas/cover.py @@ -69,13 +69,7 @@ def name(self): @cached_property def device_info(self) -> DeviceInfo: """Information about this device.""" - return { - "identifiers": {(DOMAIN, self.auto_area.config_entry.entry_id)}, - "name": NAME, - "model": VERSION, - "manufacturer": NAME, - "suggested_area": self.auto_area.area_name, - } + return self.auto_area.device_info @cached_property def unique_id(self) -> str | None: diff --git a/custom_components/auto_areas/switches/presence_lock.py b/custom_components/auto_areas/switches/presence_lock.py index 4c691ce..852a804 100644 --- a/custom_components/auto_areas/switches/presence_lock.py +++ b/custom_components/auto_areas/switches/presence_lock.py @@ -47,13 +47,7 @@ def unique_id(self) -> str | None: @cached_property def device_info(self) -> DeviceInfo: """Information about this device.""" - return { - "identifiers": {(DOMAIN, self.auto_area.config_entry.entry_id)}, - "name": NAME, - "model": VERSION, - "manufacturer": NAME, - "suggested_area": self.auto_area.area_name, - } + return self.auto_area.device_info @cached_property def device_class(self) -> SwitchDeviceClass | None: diff --git a/custom_components/auto_areas/switches/sleep_mode.py b/custom_components/auto_areas/switches/sleep_mode.py index 36d7fd0..53ab98b 100644 --- a/custom_components/auto_areas/switches/sleep_mode.py +++ b/custom_components/auto_areas/switches/sleep_mode.py @@ -47,13 +47,7 @@ def unique_id(self) -> str | None: @cached_property def device_info(self) -> DeviceInfo: """Information about this device.""" - return { - "identifiers": {(DOMAIN, self.auto_area.config_entry.entry_id)}, - "name": NAME, - "model": VERSION, - "manufacturer": NAME, - "suggested_area": self.auto_area.area_name, - } + return self.auto_area.device_info @cached_property def device_class(self) -> SwitchDeviceClass | None: From 680d3bb3d1d1528707c8cde8fdaef6604d15f2f8 Mon Sep 17 00:00:00 2001 From: Christian Stangier Date: Tue, 30 Jul 2024 20:41:54 +0200 Subject: [PATCH 2/5] Update dependencies --- custom_components/auto_areas/auto_area.py | 1 - custom_components/auto_areas/cover.py | 4 +--- custom_components/auto_areas/switches/presence_lock.py | 5 +---- custom_components/auto_areas/switches/sleep_mode.py | 5 +---- requirements.txt | 4 ++-- 5 files changed, 5 insertions(+), 14 deletions(-) diff --git a/custom_components/auto_areas/auto_area.py b/custom_components/auto_areas/auto_area.py index 34da45f..ae5ad4f 100644 --- a/custom_components/auto_areas/auto_area.py +++ b/custom_components/auto_areas/auto_area.py @@ -1,6 +1,5 @@ """Core area functionality.""" from __future__ import annotations -from token import NAME from homeassistant.core import HomeAssistant from homeassistant.helpers.area_registry import async_get as async_get_area_registry from homeassistant.helpers.device_registry import async_get as async_get_device_registry diff --git a/custom_components/auto_areas/cover.py b/custom_components/auto_areas/cover.py index a4354df..db28630 100644 --- a/custom_components/auto_areas/cover.py +++ b/custom_components/auto_areas/cover.py @@ -14,9 +14,7 @@ COVER_GROUP_ENTITY_PREFIX, COVER_GROUP_PREFIX, DOMAIN, - LOGGER, - NAME, - VERSION + LOGGER ) diff --git a/custom_components/auto_areas/switches/presence_lock.py b/custom_components/auto_areas/switches/presence_lock.py index 852a804..70026fd 100644 --- a/custom_components/auto_areas/switches/presence_lock.py +++ b/custom_components/auto_areas/switches/presence_lock.py @@ -11,11 +11,8 @@ from custom_components.auto_areas.auto_area import AutoArea from custom_components.auto_areas.const import ( - DOMAIN, LOGGER, - NAME, - PRESENCE_LOCK_SWITCH_PREFIX, - VERSION + PRESENCE_LOCK_SWITCH_PREFIX ) diff --git a/custom_components/auto_areas/switches/sleep_mode.py b/custom_components/auto_areas/switches/sleep_mode.py index 53ab98b..409a1ff 100644 --- a/custom_components/auto_areas/switches/sleep_mode.py +++ b/custom_components/auto_areas/switches/sleep_mode.py @@ -11,11 +11,8 @@ from custom_components.auto_areas.auto_area import AutoArea from custom_components.auto_areas.const import ( - DOMAIN, LOGGER, - NAME, - SLEEP_MODE_SWITCH_PREFIX, - VERSION + SLEEP_MODE_SWITCH_PREFIX ) diff --git a/requirements.txt b/requirements.txt index dc029ce..f2a93da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -# colorlog>=6.8 -homeassistant==2024.7.3 +colorlog>=6.8 +homeassistant==2024.7.4 pip>=21.3.1,<24.1 ruff==0.5.5 From 78e6ad6e581b9d009c12c40eef6b0e88d73f88cb Mon Sep 17 00:00:00 2001 From: Christian Stangier Date: Tue, 30 Jul 2024 20:49:01 +0200 Subject: [PATCH 3/5] Bump version --- custom_components/auto_areas/const.py | 2 +- custom_components/auto_areas/manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/auto_areas/const.py b/custom_components/auto_areas/const.py index d0b0b04..bad29f6 100644 --- a/custom_components/auto_areas/const.py +++ b/custom_components/auto_areas/const.py @@ -18,7 +18,7 @@ NAME = "Auto Areas" DOMAIN = "auto_areas" -VERSION = "2.0.0" +VERSION = "2.6.1" ATTRIBUTION = "Data provided by http://jsonplaceholder.typicode.com/" # diff --git a/custom_components/auto_areas/manifest.json b/custom_components/auto_areas/manifest.json index 14b6a13..ca9dfd2 100644 --- a/custom_components/auto_areas/manifest.json +++ b/custom_components/auto_areas/manifest.json @@ -23,5 +23,5 @@ "documentation": "https://github.com/c-st/auto_areas", "iot_class": "local_push", "issue_tracker": "https://github.com/c-st/auto_areas/issues", - "version": "2.1.0" + "version": "2.6.1" } \ No newline at end of file From 7c453ba51811082fb91f9fec4f7ba7fc7c17c120 Mon Sep 17 00:00:00 2001 From: Christian Stangier Date: Tue, 30 Jul 2024 20:50:03 +0200 Subject: [PATCH 4/5] Remove unused const --- custom_components/auto_areas/const.py | 1 - 1 file changed, 1 deletion(-) diff --git a/custom_components/auto_areas/const.py b/custom_components/auto_areas/const.py index bad29f6..0eb5929 100644 --- a/custom_components/auto_areas/const.py +++ b/custom_components/auto_areas/const.py @@ -19,7 +19,6 @@ NAME = "Auto Areas" DOMAIN = "auto_areas" VERSION = "2.6.1" -ATTRIBUTION = "Data provided by http://jsonplaceholder.typicode.com/" # # Naming constants From 20be661edea83d9950e547efadeed5f3b3a82674 Mon Sep 17 00:00:00 2001 From: Christian Stangier Date: Tue, 30 Jul 2024 20:50:45 +0200 Subject: [PATCH 5/5] Bump version --- custom_components/auto_areas/const.py | 2 +- custom_components/auto_areas/manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/auto_areas/const.py b/custom_components/auto_areas/const.py index 0eb5929..0c3407a 100644 --- a/custom_components/auto_areas/const.py +++ b/custom_components/auto_areas/const.py @@ -18,7 +18,7 @@ NAME = "Auto Areas" DOMAIN = "auto_areas" -VERSION = "2.6.1" +VERSION = "2.6.2" # # Naming constants diff --git a/custom_components/auto_areas/manifest.json b/custom_components/auto_areas/manifest.json index ca9dfd2..55426bd 100644 --- a/custom_components/auto_areas/manifest.json +++ b/custom_components/auto_areas/manifest.json @@ -23,5 +23,5 @@ "documentation": "https://github.com/c-st/auto_areas", "iot_class": "local_push", "issue_tracker": "https://github.com/c-st/auto_areas/issues", - "version": "2.6.1" + "version": "2.6.2" } \ No newline at end of file