Skip to content

Commit

Permalink
Merge pull request #136 from c-st/device-info
Browse files Browse the repository at this point in the history
Extract device_info to area
  • Loading branch information
c-st authored Jul 30, 2024
2 parents c418805 + 20be661 commit e8520ba
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 46 deletions.
14 changes: 14 additions & 0 deletions custom_components/auto_areas/auto_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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
Expand All @@ -20,6 +21,8 @@
ISSUE_TYPE_INVALID_AREA,
LOGGER,
RELEVANT_DOMAINS,
NAME,
VERSION
)


Expand Down Expand Up @@ -102,6 +105,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."""
Expand Down
10 changes: 2 additions & 8 deletions custom_components/auto_areas/auto_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion custom_components/auto_areas/binary_sensors/presence.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 (
Expand Down
3 changes: 1 addition & 2 deletions custom_components/auto_areas/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

NAME = "Auto Areas"
DOMAIN = "auto_areas"
VERSION = "2.0.0"
ATTRIBUTION = "Data provided by http://jsonplaceholder.typicode.com/"
VERSION = "2.6.2"

#
# Naming constants
Expand Down
12 changes: 2 additions & 10 deletions custom_components/auto_areas/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
COVER_GROUP_ENTITY_PREFIX,
COVER_GROUP_PREFIX,
DOMAIN,
LOGGER,
NAME,
VERSION
LOGGER
)


Expand Down Expand Up @@ -69,13 +67,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:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/auto_areas/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.2"
}
13 changes: 2 additions & 11 deletions custom_components/auto_areas/switches/presence_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)


Expand Down Expand Up @@ -47,13 +44,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:
Expand Down
13 changes: 2 additions & 11 deletions custom_components/auto_areas/switches/sleep_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)


Expand Down Expand Up @@ -47,13 +44,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:
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e8520ba

Please sign in to comment.