mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Add suggested area support to august (#47930)
This commit is contained in:
parent
15aa00d6cc
commit
8795608ae3
@ -5,6 +5,8 @@ from homeassistant.helpers.entity import Entity
|
|||||||
from . import DOMAIN
|
from . import DOMAIN
|
||||||
from .const import MANUFACTURER
|
from .const import MANUFACTURER
|
||||||
|
|
||||||
|
DEVICE_TYPES = ["keypad", "lock", "camera", "doorbell", "door", "bell"]
|
||||||
|
|
||||||
|
|
||||||
class AugustEntityMixin(Entity):
|
class AugustEntityMixin(Entity):
|
||||||
"""Base implementation for August device."""
|
"""Base implementation for August device."""
|
||||||
@ -31,12 +33,14 @@ class AugustEntityMixin(Entity):
|
|||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self):
|
||||||
"""Return the device_info of the device."""
|
"""Return the device_info of the device."""
|
||||||
|
name = self._device.device_name
|
||||||
return {
|
return {
|
||||||
"identifiers": {(DOMAIN, self._device_id)},
|
"identifiers": {(DOMAIN, self._device_id)},
|
||||||
"name": self._device.device_name,
|
"name": name,
|
||||||
"manufacturer": MANUFACTURER,
|
"manufacturer": MANUFACTURER,
|
||||||
"sw_version": self._detail.firmware_version,
|
"sw_version": self._detail.firmware_version,
|
||||||
"model": self._detail.model,
|
"model": self._detail.model,
|
||||||
|
"suggested_area": _remove_device_types(name, DEVICE_TYPES),
|
||||||
}
|
}
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@ -56,3 +60,19 @@ class AugustEntityMixin(Entity):
|
|||||||
self._device_id, self._update_from_data_and_write_state
|
self._device_id, self._update_from_data_and_write_state
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _remove_device_types(name, device_types):
|
||||||
|
"""Strip device types from a string.
|
||||||
|
|
||||||
|
August stores the name as Master Bed Lock
|
||||||
|
or Master Bed Door. We can come up with a
|
||||||
|
reasonable suggestion by removing the supported
|
||||||
|
device types from the string.
|
||||||
|
"""
|
||||||
|
lower_name = name.lower()
|
||||||
|
for device_type in device_types:
|
||||||
|
device_type_with_space = f" {device_type}"
|
||||||
|
if lower_name.endswith(device_type_with_space):
|
||||||
|
lower_name = lower_name[: -len(device_type_with_space)]
|
||||||
|
return name[: len(lower_name)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user