Add suggested area support to august (#47930)

This commit is contained in:
J. Nick Koston 2021-03-14 19:42:49 -10:00 committed by GitHub
parent 15aa00d6cc
commit 8795608ae3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,8 @@ from homeassistant.helpers.entity import Entity
from . import DOMAIN
from .const import MANUFACTURER
DEVICE_TYPES = ["keypad", "lock", "camera", "doorbell", "door", "bell"]
class AugustEntityMixin(Entity):
"""Base implementation for August device."""
@ -31,12 +33,14 @@ class AugustEntityMixin(Entity):
@property
def device_info(self):
"""Return the device_info of the device."""
name = self._device.device_name
return {
"identifiers": {(DOMAIN, self._device_id)},
"name": self._device.device_name,
"name": name,
"manufacturer": MANUFACTURER,
"sw_version": self._detail.firmware_version,
"model": self._detail.model,
"suggested_area": _remove_device_types(name, DEVICE_TYPES),
}
@callback
@ -56,3 +60,19 @@ class AugustEntityMixin(Entity):
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)]