Migrate Tailscale to new entity naming style (#75018)
parent
027cdbdb38
commit
13cea26e74
|
@ -41,6 +41,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
class TailscaleEntity(CoordinatorEntity):
|
||||
"""Defines a Tailscale base entity."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
|
@ -52,8 +54,6 @@ class TailscaleEntity(CoordinatorEntity):
|
|||
super().__init__(coordinator=coordinator)
|
||||
self.entity_description = description
|
||||
self.device_id = device.device_id
|
||||
self.friendly_name = device.name.split(".")[0]
|
||||
self._attr_name = f"{self.friendly_name} {description.name}"
|
||||
self._attr_unique_id = f"{device.device_id}_{description.key}"
|
||||
|
||||
@property
|
||||
|
@ -71,6 +71,6 @@ class TailscaleEntity(CoordinatorEntity):
|
|||
identifiers={(DOMAIN, device.device_id)},
|
||||
manufacturer="Tailscale Inc.",
|
||||
model=device.os,
|
||||
name=self.friendly_name,
|
||||
name=device.name.split(".")[0],
|
||||
sw_version=device.client_version,
|
||||
)
|
||||
|
|
|
@ -44,7 +44,7 @@ BINARY_SENSORS: tuple[TailscaleBinarySensorEntityDescription, ...] = (
|
|||
),
|
||||
TailscaleBinarySensorEntityDescription(
|
||||
key="client_supports_hair_pinning",
|
||||
name="Supports Hairpinning",
|
||||
name="Supports hairpinning",
|
||||
icon="mdi:wan",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
is_on_fn=lambda device: device.client_connectivity.client_supports.hair_pinning,
|
||||
|
|
|
@ -45,14 +45,14 @@ SENSORS: tuple[TailscaleSensorEntityDescription, ...] = (
|
|||
),
|
||||
TailscaleSensorEntityDescription(
|
||||
key="ip",
|
||||
name="IP Address",
|
||||
name="IP address",
|
||||
icon="mdi:ip-network",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda device: device.addresses[0] if device.addresses else None,
|
||||
),
|
||||
TailscaleSensorEntityDescription(
|
||||
key="last_seen",
|
||||
name="Last Seen",
|
||||
name="Last seen",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
value_fn=lambda device: device.last_seen,
|
||||
),
|
||||
|
|
|
@ -43,7 +43,7 @@ async def test_tailscale_binary_sensors(
|
|||
assert state.state == STATE_OFF
|
||||
assert (
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME)
|
||||
== "frencks-iphone Supports Hairpinning"
|
||||
== "frencks-iphone Supports hairpinning"
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:wan"
|
||||
assert ATTR_DEVICE_CLASS not in state.attributes
|
||||
|
|
|
@ -35,7 +35,7 @@ async def test_tailscale_sensors(
|
|||
assert entry.unique_id == "123457_last_seen"
|
||||
assert entry.entity_category is None
|
||||
assert state.state == "2021-11-15T20:37:03+00:00"
|
||||
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "router Last Seen"
|
||||
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "router Last seen"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TIMESTAMP
|
||||
assert ATTR_ICON not in state.attributes
|
||||
|
||||
|
@ -46,7 +46,7 @@ async def test_tailscale_sensors(
|
|||
assert entry.unique_id == "123457_ip"
|
||||
assert entry.entity_category == EntityCategory.DIAGNOSTIC
|
||||
assert state.state == "100.11.11.112"
|
||||
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "router IP Address"
|
||||
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "router IP address"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:ip-network"
|
||||
assert ATTR_DEVICE_CLASS not in state.attributes
|
||||
|
||||
|
|
Loading…
Reference in New Issue