mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 00:37:13 +00:00
Migrate Whois to new entity naming style (#75019)
This commit is contained in:
parent
1d2e64e3dc
commit
2aa98da624
@ -79,7 +79,7 @@ SENSORS: tuple[WhoisSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
WhoisSensorEntityDescription(
|
WhoisSensorEntityDescription(
|
||||||
key="days_until_expiration",
|
key="days_until_expiration",
|
||||||
name="Days Until Expiration",
|
name="Days until expiration",
|
||||||
icon="mdi:calendar-clock",
|
icon="mdi:calendar-clock",
|
||||||
native_unit_of_measurement=TIME_DAYS,
|
native_unit_of_measurement=TIME_DAYS,
|
||||||
value_fn=_days_until_expiration,
|
value_fn=_days_until_expiration,
|
||||||
@ -93,7 +93,7 @@ SENSORS: tuple[WhoisSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
WhoisSensorEntityDescription(
|
WhoisSensorEntityDescription(
|
||||||
key="last_updated",
|
key="last_updated",
|
||||||
name="Last Updated",
|
name="Last updated",
|
||||||
device_class=SensorDeviceClass.TIMESTAMP,
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
value_fn=lambda domain: _ensure_timezone(domain.last_updated),
|
value_fn=lambda domain: _ensure_timezone(domain.last_updated),
|
||||||
@ -156,6 +156,7 @@ class WhoisSensorEntity(CoordinatorEntity, SensorEntity):
|
|||||||
"""Implementation of a WHOIS sensor."""
|
"""Implementation of a WHOIS sensor."""
|
||||||
|
|
||||||
entity_description: WhoisSensorEntityDescription
|
entity_description: WhoisSensorEntityDescription
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -166,10 +167,10 @@ class WhoisSensorEntity(CoordinatorEntity, SensorEntity):
|
|||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(coordinator=coordinator)
|
super().__init__(coordinator=coordinator)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_name = f"{domain} {description.name}"
|
|
||||||
self._attr_unique_id = f"{domain}_{description.key}"
|
self._attr_unique_id = f"{domain}_{description.key}"
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
identifiers={(DOMAIN, domain)},
|
identifiers={(DOMAIN, domain)},
|
||||||
|
name=domain,
|
||||||
entry_type=DeviceEntryType.SERVICE,
|
entry_type=DeviceEntryType.SERVICE,
|
||||||
)
|
)
|
||||||
self._domain = domain
|
self._domain = domain
|
||||||
|
@ -60,7 +60,7 @@ async def test_whois_sensors(
|
|||||||
assert state.state == "364"
|
assert state.state == "364"
|
||||||
assert (
|
assert (
|
||||||
state.attributes.get(ATTR_FRIENDLY_NAME)
|
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 state.attributes.get(ATTR_ICON) == "mdi:calendar-clock"
|
||||||
assert ATTR_DEVICE_CLASS not in state.attributes
|
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.unique_id == "home-assistant.io_last_updated"
|
||||||
assert entry.entity_category == EntityCategory.DIAGNOSTIC
|
assert entry.entity_category == EntityCategory.DIAGNOSTIC
|
||||||
assert state.state == "2021-12-31T23:00:00+00:00"
|
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 state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TIMESTAMP
|
||||||
assert ATTR_ICON not in state.attributes
|
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.configuration_url is None
|
||||||
assert device_entry.entry_type == dr.DeviceEntryType.SERVICE
|
assert device_entry.entry_type == dr.DeviceEntryType.SERVICE
|
||||||
assert device_entry.identifiers == {(DOMAIN, "home-assistant.io")}
|
assert device_entry.identifiers == {(DOMAIN, "home-assistant.io")}
|
||||||
|
assert device_entry.name == "home-assistant.io"
|
||||||
assert device_entry.manufacturer is None
|
assert device_entry.manufacturer is None
|
||||||
assert device_entry.model is None
|
assert device_entry.model is None
|
||||||
assert device_entry.name is None
|
|
||||||
assert device_entry.sw_version 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.unique_id == "home-assistant.io_last_updated"
|
||||||
assert entry.entity_category == EntityCategory.DIAGNOSTIC
|
assert entry.entity_category == EntityCategory.DIAGNOSTIC
|
||||||
assert state.state == "2021-12-31T23:00:00+00:00"
|
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 state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TIMESTAMP
|
||||||
assert ATTR_ICON not in state.attributes
|
assert ATTR_ICON not in state.attributes
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user