From edf304718cefc0f218c55f1170f038f82801ac1b Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Sun, 10 Jul 2022 13:41:12 -0600 Subject: [PATCH] Migrate Notion to new entity naming style (#74746) --- homeassistant/components/notion/__init__.py | 12 +++++++++--- homeassistant/components/notion/binary_sensor.py | 14 +++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/notion/__init__.py b/homeassistant/components/notion/__init__.py index 49277740f56..2a73d12d946 100644 --- a/homeassistant/components/notion/__init__.py +++ b/homeassistant/components/notion/__init__.py @@ -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"]}' ) diff --git a/homeassistant/components/notion/binary_sensor.py b/homeassistant/components/notion/binary_sensor.py index 57c70849a9a..2a34724837d 100644 --- a/homeassistant/components/notion/binary_sensor.py +++ b/homeassistant/components/notion/binary_sensor.py @@ -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", ),