Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Notion to new entity naming style #74746

Merged
merged 3 commits into from Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions homeassistant/components/notion/__init__.py
Expand Up @@ -118,20 +118,27 @@ 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"],
)


class NotionEntity(CoordinatorEntity):
"""Define a base Notion entity."""

_attr_has_entity_name = True

def __init__(
self,
coordinator: DataUpdateCoordinator,
Expand All @@ -150,13 +157,12 @@ def __init__(
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"]}'
)
Expand Down
14 changes: 7 additions & 7 deletions homeassistant/components/notion/binary_sensor.py
Expand Up @@ -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",
Expand All @@ -61,13 +61,13 @@ class NotionBinarySensorDescription(
),
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",
),
Expand All @@ -86,25 +86,25 @@ class NotionBinarySensorDescription(
),
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",
),
Expand Down