Skip to content

Commit e8520ba

Browse files
authored
Merge pull request #136 from c-st/device-info
Extract device_info to area
2 parents c418805 + 20be661 commit e8520ba

File tree

9 files changed

+28
-46
lines changed

9 files changed

+28
-46
lines changed

custom_components/auto_areas/auto_area.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from homeassistant.helpers.area_registry import async_get as async_get_area_registry
55
from homeassistant.helpers.device_registry import async_get as async_get_device_registry
66
from homeassistant.helpers.entity_registry import async_get as async_get_entity_registry
7+
from homeassistant.helpers.device_registry import DeviceInfo
78
from homeassistant.helpers.issue_registry import async_create_issue, IssueSeverity
89
from homeassistant.config_entries import ConfigEntry
910
from homeassistant.util import slugify
@@ -20,6 +21,8 @@
2021
ISSUE_TYPE_INVALID_AREA,
2122
LOGGER,
2223
RELEVANT_DOMAINS,
24+
NAME,
25+
VERSION
2326
)
2427

2528

@@ -102,6 +105,17 @@ def get_area_entity_ids(self, device_classes: list[str]) -> list[str]:
102105
or entity.original_device_class in device_classes
103106
]
104107

108+
@property
109+
def device_info(self) -> DeviceInfo:
110+
"""Information about this device."""
111+
return {
112+
"identifiers": {(DOMAIN, self.config_entry.entry_id)},
113+
"name": NAME,
114+
"model": VERSION,
115+
"manufacturer": NAME,
116+
"suggested_area": self.area_name,
117+
}
118+
105119
@property
106120
def area_name(self) -> str:
107121
"""Return area name or fallback."""

custom_components/auto_areas/auto_entity.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from custom_components.auto_areas.calculations import get_calculation
1717

1818
from .auto_area import AutoArea
19-
from .const import DOMAIN, LOGGER, NAME, VERSION
19+
from .const import LOGGER
2020

2121
_TEntity = TypeVar("_TEntity", bound=Entity)
2222
_TDeviceClass = TypeVar(
@@ -83,13 +83,7 @@ def device_class(self) -> _TDeviceClass:
8383
@cached_property
8484
def device_info(self) -> DeviceInfo:
8585
"""Information about this device."""
86-
return {
87-
"identifiers": {(DOMAIN, self.auto_area.config_entry.entry_id)},
88-
"name": NAME,
89-
"model": VERSION,
90-
"manufacturer": NAME,
91-
"suggested_area": self.auto_area.area_name,
92-
}
86+
return self.auto_area.device_info
9387

9488
@cached_property
9589
def suggested_display_precision(self) -> int | None:

custom_components/auto_areas/binary_sensors/presence.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Presence binary sensor."""
22

33
from __future__ import annotations
4-
from custom_components.auto_areas.ha_helpers import all_states_are_off
54

65
from functools import cached_property
76
from typing import Literal, override
@@ -12,6 +11,8 @@
1211
BinarySensorEntity,
1312
)
1413
from homeassistant.helpers.event import async_track_state_change_event
14+
15+
from custom_components.auto_areas.ha_helpers import all_states_are_off
1516
from custom_components.auto_areas.auto_area import AutoArea
1617
from custom_components.auto_areas.auto_entity import AutoEntity
1718
from custom_components.auto_areas.const import (

custom_components/auto_areas/const.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
NAME = "Auto Areas"
2020
DOMAIN = "auto_areas"
21-
VERSION = "2.0.0"
22-
ATTRIBUTION = "Data provided by http://jsonplaceholder.typicode.com/"
21+
VERSION = "2.6.2"
2322

2423
#
2524
# Naming constants

custom_components/auto_areas/cover.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
COVER_GROUP_ENTITY_PREFIX,
1515
COVER_GROUP_PREFIX,
1616
DOMAIN,
17-
LOGGER,
18-
NAME,
19-
VERSION
17+
LOGGER
2018
)
2119

2220

@@ -69,13 +67,7 @@ def name(self):
6967
@cached_property
7068
def device_info(self) -> DeviceInfo:
7169
"""Information about this device."""
72-
return {
73-
"identifiers": {(DOMAIN, self.auto_area.config_entry.entry_id)},
74-
"name": NAME,
75-
"model": VERSION,
76-
"manufacturer": NAME,
77-
"suggested_area": self.auto_area.area_name,
78-
}
70+
return self.auto_area.device_info
7971

8072
@cached_property
8173
def unique_id(self) -> str | None:

custom_components/auto_areas/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
"documentation": "https://github.com/c-st/auto_areas",
2424
"iot_class": "local_push",
2525
"issue_tracker": "https://github.com/c-st/auto_areas/issues",
26-
"version": "2.1.0"
26+
"version": "2.6.2"
2727
}

custom_components/auto_areas/switches/presence_lock.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111

1212
from custom_components.auto_areas.auto_area import AutoArea
1313
from custom_components.auto_areas.const import (
14-
DOMAIN,
1514
LOGGER,
16-
NAME,
17-
PRESENCE_LOCK_SWITCH_PREFIX,
18-
VERSION
15+
PRESENCE_LOCK_SWITCH_PREFIX
1916
)
2017

2118

@@ -47,13 +44,7 @@ def unique_id(self) -> str | None:
4744
@cached_property
4845
def device_info(self) -> DeviceInfo:
4946
"""Information about this device."""
50-
return {
51-
"identifiers": {(DOMAIN, self.auto_area.config_entry.entry_id)},
52-
"name": NAME,
53-
"model": VERSION,
54-
"manufacturer": NAME,
55-
"suggested_area": self.auto_area.area_name,
56-
}
47+
return self.auto_area.device_info
5748

5849
@cached_property
5950
def device_class(self) -> SwitchDeviceClass | None:

custom_components/auto_areas/switches/sleep_mode.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111

1212
from custom_components.auto_areas.auto_area import AutoArea
1313
from custom_components.auto_areas.const import (
14-
DOMAIN,
1514
LOGGER,
16-
NAME,
17-
SLEEP_MODE_SWITCH_PREFIX,
18-
VERSION
15+
SLEEP_MODE_SWITCH_PREFIX
1916
)
2017

2118

@@ -47,13 +44,7 @@ def unique_id(self) -> str | None:
4744
@cached_property
4845
def device_info(self) -> DeviceInfo:
4946
"""Information about this device."""
50-
return {
51-
"identifiers": {(DOMAIN, self.auto_area.config_entry.entry_id)},
52-
"name": NAME,
53-
"model": VERSION,
54-
"manufacturer": NAME,
55-
"suggested_area": self.auto_area.area_name,
56-
}
47+
return self.auto_area.device_info
5748

5849
@cached_property
5950
def device_class(self) -> SwitchDeviceClass | None:

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# colorlog>=6.8
2-
homeassistant==2024.7.3
1+
colorlog>=6.8
2+
homeassistant==2024.7.4
33
pip>=21.3.1,<24.1
44
ruff==0.5.5

0 commit comments

Comments
 (0)