Migrate Whois to new entity naming style (#75019)

This commit is contained in:
Franck Nijhof 2022-07-14 10:56:01 +02:00 committed by GitHub
parent 1d2e64e3dc
commit 2aa98da624
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -79,7 +79,7 @@ SENSORS: tuple[WhoisSensorEntityDescription, ...] = (
),
WhoisSensorEntityDescription(
key="days_until_expiration",
name="Days Until Expiration",
name="Days until expiration",
icon="mdi:calendar-clock",
native_unit_of_measurement=TIME_DAYS,
value_fn=_days_until_expiration,
@ -93,7 +93,7 @@ SENSORS: tuple[WhoisSensorEntityDescription, ...] = (
),
WhoisSensorEntityDescription(
key="last_updated",
name="Last Updated",
name="Last updated",
device_class=SensorDeviceClass.TIMESTAMP,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda domain: _ensure_timezone(domain.last_updated),
@ -156,6 +156,7 @@ class WhoisSensorEntity(CoordinatorEntity, SensorEntity):
"""Implementation of a WHOIS sensor."""
entity_description: WhoisSensorEntityDescription
_attr_has_entity_name = True
def __init__(
self,
@ -166,10 +167,10 @@ class WhoisSensorEntity(CoordinatorEntity, SensorEntity):
"""Initialize the sensor."""
super().__init__(coordinator=coordinator)
self.entity_description = description
self._attr_name = f"{domain} {description.name}"
self._attr_unique_id = f"{domain}_{description.key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, domain)},
name=domain,
entry_type=DeviceEntryType.SERVICE,
)
self._domain = domain

View File

@ -60,7 +60,7 @@ async def test_whois_sensors(
assert state.state == "364"
assert (
state.attributes.get(ATTR_FRIENDLY_NAME)
== "home-assistant.io Days Until Expiration"
== "home-assistant.io Days until expiration"
)
assert state.attributes.get(ATTR_ICON) == "mdi:calendar-clock"
assert ATTR_DEVICE_CLASS not in state.attributes
@ -83,7 +83,7 @@ async def test_whois_sensors(
assert entry.unique_id == "home-assistant.io_last_updated"
assert entry.entity_category == EntityCategory.DIAGNOSTIC
assert state.state == "2021-12-31T23:00:00+00:00"
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "home-assistant.io Last Updated"
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "home-assistant.io Last updated"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TIMESTAMP
assert ATTR_ICON not in state.attributes
@ -137,9 +137,9 @@ async def test_whois_sensors(
assert device_entry.configuration_url is None
assert device_entry.entry_type == dr.DeviceEntryType.SERVICE
assert device_entry.identifiers == {(DOMAIN, "home-assistant.io")}
assert device_entry.name == "home-assistant.io"
assert device_entry.manufacturer is None
assert device_entry.model is None
assert device_entry.name is None
assert device_entry.sw_version is None
@ -159,7 +159,7 @@ async def test_whois_sensors_missing_some_attrs(
assert entry.unique_id == "home-assistant.io_last_updated"
assert entry.entity_category == EntityCategory.DIAGNOSTIC
assert state.state == "2021-12-31T23:00:00+00:00"
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "home-assistant.io Last Updated"
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "home-assistant.io Last updated"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TIMESTAMP
assert ATTR_ICON not in state.attributes