Migrate SimpliSafe to new entity naming style (#74763)

This commit is contained in:
Aaron Bach 2022-07-09 11:59:36 -06:00 committed by GitHub
parent 5360e56d09
commit ea1fc6b5d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 8 deletions

View File

@ -113,8 +113,7 @@ ATTR_SYSTEM_ID = "system_id"
ATTR_TIMESTAMP = "timestamp" ATTR_TIMESTAMP = "timestamp"
DEFAULT_CONFIG_URL = "https://webapp.simplisafe.com/new/#/dashboard" DEFAULT_CONFIG_URL = "https://webapp.simplisafe.com/new/#/dashboard"
DEFAULT_ENTITY_MODEL = "alarm_control_panel" DEFAULT_ENTITY_MODEL = "Alarm control panel"
DEFAULT_ENTITY_NAME = "Alarm Control Panel"
DEFAULT_ERROR_THRESHOLD = 2 DEFAULT_ERROR_THRESHOLD = 2
DEFAULT_SCAN_INTERVAL = timedelta(seconds=30) DEFAULT_SCAN_INTERVAL = timedelta(seconds=30)
DEFAULT_SOCKET_MIN_RETRY = 15 DEFAULT_SOCKET_MIN_RETRY = 15
@ -660,6 +659,8 @@ class SimpliSafe:
class SimpliSafeEntity(CoordinatorEntity): class SimpliSafeEntity(CoordinatorEntity):
"""Define a base SimpliSafe entity.""" """Define a base SimpliSafe entity."""
_attr_has_entity_name = True
def __init__( def __init__(
self, self,
simplisafe: SimpliSafe, simplisafe: SimpliSafe,
@ -679,12 +680,11 @@ class SimpliSafeEntity(CoordinatorEntity):
self._error_count = 0 self._error_count = 0
if device: if device:
model = device.type.name model = device.type.name.capitalize().replace("_", " ")
device_name = device.name device_name = f"{device.name.capitalize()} {model}"
serial = device.serial serial = device.serial
else: else:
model = DEFAULT_ENTITY_MODEL model = device_name = DEFAULT_ENTITY_MODEL
device_name = DEFAULT_ENTITY_NAME
serial = system.serial serial = system.serial
event = simplisafe.initial_event_to_use[system.system_id] event = simplisafe.initial_event_to_use[system.system_id]
@ -714,7 +714,6 @@ class SimpliSafeEntity(CoordinatorEntity):
via_device=(DOMAIN, system.system_id), via_device=(DOMAIN, system.system_id),
) )
self._attr_name = f"{system.address} {device_name} {' '.join([w.title() for w in model.split('_')])}"
self._attr_unique_id = serial self._attr_unique_id = serial
self._device = device self._device = device
self._online = True self._online = True

View File

@ -103,7 +103,7 @@ class BatteryBinarySensor(SimpliSafeEntity, BinarySensorEntity):
"""Initialize.""" """Initialize."""
super().__init__(simplisafe, system, device=sensor) super().__init__(simplisafe, system, device=sensor)
self._attr_name = f"{super().name} Battery" self._attr_name = "Battery"
self._attr_unique_id = f"{super().unique_id}-battery" self._attr_unique_id = f"{super().unique_id}-battery"
self._device: SensorV3 self._device: SensorV3