Migrate Notion to new entity naming style (#74746)
This commit is contained in:
parent
5971ab6549
commit
edf304718c
2 changed files with 16 additions and 10 deletions
|
@ -118,13 +118,18 @@ def _async_register_new_bridge(
|
||||||
hass: HomeAssistant, bridge: dict, entry: ConfigEntry
|
hass: HomeAssistant, bridge: dict, entry: ConfigEntry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Register a new bridge."""
|
"""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 = dr.async_get(hass)
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
config_entry_id=entry.entry_id,
|
config_entry_id=entry.entry_id,
|
||||||
identifiers={(DOMAIN, bridge["hardware_id"])},
|
identifiers={(DOMAIN, bridge["hardware_id"])},
|
||||||
manufacturer="Silicon Labs",
|
manufacturer="Silicon Labs",
|
||||||
model=bridge["hardware_revision"],
|
model=bridge["hardware_revision"],
|
||||||
name=bridge["name"] or bridge["id"],
|
name=bridge_name,
|
||||||
sw_version=bridge["firmware_version"]["wifi"],
|
sw_version=bridge["firmware_version"]["wifi"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -132,6 +137,8 @@ def _async_register_new_bridge(
|
||||||
class NotionEntity(CoordinatorEntity):
|
class NotionEntity(CoordinatorEntity):
|
||||||
"""Define a base Notion entity."""
|
"""Define a base Notion entity."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: DataUpdateCoordinator,
|
coordinator: DataUpdateCoordinator,
|
||||||
|
@ -150,13 +157,12 @@ class NotionEntity(CoordinatorEntity):
|
||||||
identifiers={(DOMAIN, sensor["hardware_id"])},
|
identifiers={(DOMAIN, sensor["hardware_id"])},
|
||||||
manufacturer="Silicon Labs",
|
manufacturer="Silicon Labs",
|
||||||
model=sensor["hardware_revision"],
|
model=sensor["hardware_revision"],
|
||||||
name=str(sensor["name"]),
|
name=str(sensor["name"]).capitalize(),
|
||||||
sw_version=sensor["firmware_version"],
|
sw_version=sensor["firmware_version"],
|
||||||
via_device=(DOMAIN, bridge.get("hardware_id")),
|
via_device=(DOMAIN, bridge.get("hardware_id")),
|
||||||
)
|
)
|
||||||
|
|
||||||
self._attr_extra_state_attributes = {}
|
self._attr_extra_state_attributes = {}
|
||||||
self._attr_name = f'{sensor["name"]}: {description.name}'
|
|
||||||
self._attr_unique_id = (
|
self._attr_unique_id = (
|
||||||
f'{sensor_id}_{coordinator.data["tasks"][task_id]["task_type"]}'
|
f'{sensor_id}_{coordinator.data["tasks"][task_id]["task_type"]}'
|
||||||
)
|
)
|
||||||
|
|
|
@ -48,7 +48,7 @@ class NotionBinarySensorDescription(
|
||||||
BINARY_SENSOR_DESCRIPTIONS = (
|
BINARY_SENSOR_DESCRIPTIONS = (
|
||||||
NotionBinarySensorDescription(
|
NotionBinarySensorDescription(
|
||||||
key=SENSOR_BATTERY,
|
key=SENSOR_BATTERY,
|
||||||
name="Low Battery",
|
name="Low battery",
|
||||||
device_class=BinarySensorDeviceClass.BATTERY,
|
device_class=BinarySensorDeviceClass.BATTERY,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
on_state="critical",
|
on_state="critical",
|
||||||
|
@ -61,13 +61,13 @@ BINARY_SENSOR_DESCRIPTIONS = (
|
||||||
),
|
),
|
||||||
NotionBinarySensorDescription(
|
NotionBinarySensorDescription(
|
||||||
key=SENSOR_GARAGE_DOOR,
|
key=SENSOR_GARAGE_DOOR,
|
||||||
name="Garage Door",
|
name="Garage door",
|
||||||
device_class=BinarySensorDeviceClass.GARAGE_DOOR,
|
device_class=BinarySensorDeviceClass.GARAGE_DOOR,
|
||||||
on_state="open",
|
on_state="open",
|
||||||
),
|
),
|
||||||
NotionBinarySensorDescription(
|
NotionBinarySensorDescription(
|
||||||
key=SENSOR_LEAK,
|
key=SENSOR_LEAK,
|
||||||
name="Leak Detector",
|
name="Leak detector",
|
||||||
device_class=BinarySensorDeviceClass.MOISTURE,
|
device_class=BinarySensorDeviceClass.MOISTURE,
|
||||||
on_state="leak",
|
on_state="leak",
|
||||||
),
|
),
|
||||||
|
@ -86,25 +86,25 @@ BINARY_SENSOR_DESCRIPTIONS = (
|
||||||
),
|
),
|
||||||
NotionBinarySensorDescription(
|
NotionBinarySensorDescription(
|
||||||
key=SENSOR_SLIDING,
|
key=SENSOR_SLIDING,
|
||||||
name="Sliding Door/Window",
|
name="Sliding door/window",
|
||||||
device_class=BinarySensorDeviceClass.DOOR,
|
device_class=BinarySensorDeviceClass.DOOR,
|
||||||
on_state="open",
|
on_state="open",
|
||||||
),
|
),
|
||||||
NotionBinarySensorDescription(
|
NotionBinarySensorDescription(
|
||||||
key=SENSOR_SMOKE_CO,
|
key=SENSOR_SMOKE_CO,
|
||||||
name="Smoke/Carbon Monoxide Detector",
|
name="Smoke/Carbon monoxide detector",
|
||||||
device_class=BinarySensorDeviceClass.SMOKE,
|
device_class=BinarySensorDeviceClass.SMOKE,
|
||||||
on_state="alarm",
|
on_state="alarm",
|
||||||
),
|
),
|
||||||
NotionBinarySensorDescription(
|
NotionBinarySensorDescription(
|
||||||
key=SENSOR_WINDOW_HINGED_HORIZONTAL,
|
key=SENSOR_WINDOW_HINGED_HORIZONTAL,
|
||||||
name="Hinged Window",
|
name="Hinged window",
|
||||||
device_class=BinarySensorDeviceClass.WINDOW,
|
device_class=BinarySensorDeviceClass.WINDOW,
|
||||||
on_state="open",
|
on_state="open",
|
||||||
),
|
),
|
||||||
NotionBinarySensorDescription(
|
NotionBinarySensorDescription(
|
||||||
key=SENSOR_WINDOW_HINGED_VERTICAL,
|
key=SENSOR_WINDOW_HINGED_VERTICAL,
|
||||||
name="Hinged Window",
|
name="Hinged window",
|
||||||
device_class=BinarySensorDeviceClass.WINDOW,
|
device_class=BinarySensorDeviceClass.WINDOW,
|
||||||
on_state="open",
|
on_state="open",
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Reference in a new issue