Migrate Notion to new entity naming style (#74746)

pull/74930/head
Aaron Bach 2022-07-10 13:41:12 -06:00 committed by GitHub
parent 5971ab6549
commit edf304718c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View File

@ -118,13 +118,18 @@ def _async_register_new_bridge(
hass: HomeAssistant, bridge: dict, entry: ConfigEntry
) -> None:
"""Register a new bridge."""
if name := bridge["name"]:
bridge_name = name.capitalize()
else:
bridge_name = bridge["id"]
device_registry = dr.async_get(hass)
device_registry.async_get_or_create(
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, bridge["hardware_id"])},
manufacturer="Silicon Labs",
model=bridge["hardware_revision"],
name=bridge["name"] or bridge["id"],
name=bridge_name,
sw_version=bridge["firmware_version"]["wifi"],
)
@ -132,6 +137,8 @@ def _async_register_new_bridge(
class NotionEntity(CoordinatorEntity):
"""Define a base Notion entity."""
_attr_has_entity_name = True
def __init__(
self,
coordinator: DataUpdateCoordinator,
@ -150,13 +157,12 @@ class NotionEntity(CoordinatorEntity):
identifiers={(DOMAIN, sensor["hardware_id"])},
manufacturer="Silicon Labs",
model=sensor["hardware_revision"],
name=str(sensor["name"]),
name=str(sensor["name"]).capitalize(),
sw_version=sensor["firmware_version"],
via_device=(DOMAIN, bridge.get("hardware_id")),
)
self._attr_extra_state_attributes = {}
self._attr_name = f'{sensor["name"]}: {description.name}'
self._attr_unique_id = (
f'{sensor_id}_{coordinator.data["tasks"][task_id]["task_type"]}'
)

View File

@ -48,7 +48,7 @@ class NotionBinarySensorDescription(
BINARY_SENSOR_DESCRIPTIONS = (
NotionBinarySensorDescription(
key=SENSOR_BATTERY,
name="Low Battery",
name="Low battery",
device_class=BinarySensorDeviceClass.BATTERY,
entity_category=EntityCategory.DIAGNOSTIC,
on_state="critical",
@ -61,13 +61,13 @@ BINARY_SENSOR_DESCRIPTIONS = (
),
NotionBinarySensorDescription(
key=SENSOR_GARAGE_DOOR,
name="Garage Door",
name="Garage door",
device_class=BinarySensorDeviceClass.GARAGE_DOOR,
on_state="open",
),
NotionBinarySensorDescription(
key=SENSOR_LEAK,
name="Leak Detector",
name="Leak detector",
device_class=BinarySensorDeviceClass.MOISTURE,
on_state="leak",
),
@ -86,25 +86,25 @@ BINARY_SENSOR_DESCRIPTIONS = (
),
NotionBinarySensorDescription(
key=SENSOR_SLIDING,
name="Sliding Door/Window",
name="Sliding door/window",
device_class=BinarySensorDeviceClass.DOOR,
on_state="open",
),
NotionBinarySensorDescription(
key=SENSOR_SMOKE_CO,
name="Smoke/Carbon Monoxide Detector",
name="Smoke/Carbon monoxide detector",
device_class=BinarySensorDeviceClass.SMOKE,
on_state="alarm",
),
NotionBinarySensorDescription(
key=SENSOR_WINDOW_HINGED_HORIZONTAL,
name="Hinged Window",
name="Hinged window",
device_class=BinarySensorDeviceClass.WINDOW,
on_state="open",
),
NotionBinarySensorDescription(
key=SENSOR_WINDOW_HINGED_VERTICAL,
name="Hinged Window",
name="Hinged window",
device_class=BinarySensorDeviceClass.WINDOW,
on_state="open",
),