From 8795608ae31fa8e95424371a260e31778bef802a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 14 Mar 2021 19:42:49 -1000 Subject: [PATCH] Add suggested area support to august (#47930) --- homeassistant/components/august/entity.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/august/entity.py b/homeassistant/components/august/entity.py index b6c677a63b6..b2a93948449 100644 --- a/homeassistant/components/august/entity.py +++ b/homeassistant/components/august/entity.py @@ -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)]