Migrate RDW to new entity naming style (#75017)

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

View file

@ -41,13 +41,13 @@ class RDWBinarySensorEntityDescription(
BINARY_SENSORS: tuple[RDWBinarySensorEntityDescription, ...] = ( BINARY_SENSORS: tuple[RDWBinarySensorEntityDescription, ...] = (
RDWBinarySensorEntityDescription( RDWBinarySensorEntityDescription(
key="liability_insured", key="liability_insured",
name="Liability Insured", name="Liability insured",
icon="mdi:shield-car", icon="mdi:shield-car",
is_on_fn=lambda vehicle: vehicle.liability_insured, is_on_fn=lambda vehicle: vehicle.liability_insured,
), ),
RDWBinarySensorEntityDescription( RDWBinarySensorEntityDescription(
key="pending_recall", key="pending_recall",
name="Pending Recall", name="Pending recall",
device_class=BinarySensorDeviceClass.PROBLEM, device_class=BinarySensorDeviceClass.PROBLEM,
is_on_fn=lambda vehicle: vehicle.pending_recall, is_on_fn=lambda vehicle: vehicle.pending_recall,
), ),
@ -75,6 +75,7 @@ class RDWBinarySensorEntity(CoordinatorEntity, BinarySensorEntity):
"""Defines an RDW binary sensor.""" """Defines an RDW binary sensor."""
entity_description: RDWBinarySensorEntityDescription entity_description: RDWBinarySensorEntityDescription
_attr_has_entity_name = True
def __init__( def __init__(
self, self,
@ -91,7 +92,7 @@ class RDWBinarySensorEntity(CoordinatorEntity, BinarySensorEntity):
entry_type=DeviceEntryType.SERVICE, entry_type=DeviceEntryType.SERVICE,
identifiers={(DOMAIN, coordinator.data.license_plate)}, identifiers={(DOMAIN, coordinator.data.license_plate)},
manufacturer=coordinator.data.brand, manufacturer=coordinator.data.brand,
name=f"{coordinator.data.brand}: {coordinator.data.license_plate}", name=f"{coordinator.data.brand} {coordinator.data.license_plate}",
model=coordinator.data.model, model=coordinator.data.model,
configuration_url=f"https://ovi.rdw.nl/default.aspx?kenteken={coordinator.data.license_plate}", configuration_url=f"https://ovi.rdw.nl/default.aspx?kenteken={coordinator.data.license_plate}",
) )

View file

@ -42,13 +42,13 @@ class RDWSensorEntityDescription(
SENSORS: tuple[RDWSensorEntityDescription, ...] = ( SENSORS: tuple[RDWSensorEntityDescription, ...] = (
RDWSensorEntityDescription( RDWSensorEntityDescription(
key="apk_expiration", key="apk_expiration",
name="APK Expiration", name="APK expiration",
device_class=SensorDeviceClass.DATE, device_class=SensorDeviceClass.DATE,
value_fn=lambda vehicle: vehicle.apk_expiration, value_fn=lambda vehicle: vehicle.apk_expiration,
), ),
RDWSensorEntityDescription( RDWSensorEntityDescription(
key="ascription_date", key="ascription_date",
name="Ascription Date", name="Ascription date",
device_class=SensorDeviceClass.DATE, device_class=SensorDeviceClass.DATE,
value_fn=lambda vehicle: vehicle.ascription_date, value_fn=lambda vehicle: vehicle.ascription_date,
), ),
@ -76,6 +76,7 @@ class RDWSensorEntity(CoordinatorEntity, SensorEntity):
"""Defines an RDW sensor.""" """Defines an RDW sensor."""
entity_description: RDWSensorEntityDescription entity_description: RDWSensorEntityDescription
_attr_has_entity_name = True
def __init__( def __init__(
self, self,
@ -93,7 +94,7 @@ class RDWSensorEntity(CoordinatorEntity, SensorEntity):
entry_type=DeviceEntryType.SERVICE, entry_type=DeviceEntryType.SERVICE,
identifiers={(DOMAIN, f"{license_plate}")}, identifiers={(DOMAIN, f"{license_plate}")},
manufacturer=coordinator.data.brand, manufacturer=coordinator.data.brand,
name=f"{coordinator.data.brand}: {coordinator.data.license_plate}", name=f"{coordinator.data.brand} {coordinator.data.license_plate}",
model=coordinator.data.model, model=coordinator.data.model,
configuration_url=f"https://ovi.rdw.nl/default.aspx?kenteken={coordinator.data.license_plate}", configuration_url=f"https://ovi.rdw.nl/default.aspx?kenteken={coordinator.data.license_plate}",
) )

View file

@ -16,23 +16,23 @@ async def test_vehicle_binary_sensors(
entity_registry = er.async_get(hass) entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass) device_registry = dr.async_get(hass)
state = hass.states.get("binary_sensor.liability_insured") state = hass.states.get("binary_sensor.skoda_11zkz3_liability_insured")
entry = entity_registry.async_get("binary_sensor.liability_insured") entry = entity_registry.async_get("binary_sensor.skoda_11zkz3_liability_insured")
assert entry assert entry
assert state assert state
assert entry.unique_id == "11ZKZ3_liability_insured" assert entry.unique_id == "11ZKZ3_liability_insured"
assert state.state == "off" assert state.state == "off"
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Liability Insured" assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Skoda 11ZKZ3 Liability insured"
assert state.attributes.get(ATTR_ICON) == "mdi:shield-car" assert state.attributes.get(ATTR_ICON) == "mdi:shield-car"
assert ATTR_DEVICE_CLASS not in state.attributes assert ATTR_DEVICE_CLASS not in state.attributes
state = hass.states.get("binary_sensor.pending_recall") state = hass.states.get("binary_sensor.skoda_11zkz3_pending_recall")
entry = entity_registry.async_get("binary_sensor.pending_recall") entry = entity_registry.async_get("binary_sensor.skoda_11zkz3_pending_recall")
assert entry assert entry
assert state assert state
assert entry.unique_id == "11ZKZ3_pending_recall" assert entry.unique_id == "11ZKZ3_pending_recall"
assert state.state == "off" assert state.state == "off"
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Pending Recall" assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Skoda 11ZKZ3 Pending recall"
assert state.attributes.get(ATTR_DEVICE_CLASS) == BinarySensorDeviceClass.PROBLEM assert state.attributes.get(ATTR_DEVICE_CLASS) == BinarySensorDeviceClass.PROBLEM
assert ATTR_ICON not in state.attributes assert ATTR_ICON not in state.attributes
@ -41,7 +41,7 @@ async def test_vehicle_binary_sensors(
assert device_entry assert device_entry
assert device_entry.identifiers == {(DOMAIN, "11ZKZ3")} assert device_entry.identifiers == {(DOMAIN, "11ZKZ3")}
assert device_entry.manufacturer == "Skoda" assert device_entry.manufacturer == "Skoda"
assert device_entry.name == "Skoda: 11ZKZ3" assert device_entry.name == "Skoda 11ZKZ3"
assert device_entry.entry_type is dr.DeviceEntryType.SERVICE assert device_entry.entry_type is dr.DeviceEntryType.SERVICE
assert device_entry.model == "Citigo" assert device_entry.model == "Citigo"
assert ( assert (

View file

@ -21,25 +21,25 @@ async def test_vehicle_sensors(
entity_registry = er.async_get(hass) entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass) device_registry = dr.async_get(hass)
state = hass.states.get("sensor.apk_expiration") state = hass.states.get("sensor.skoda_11zkz3_apk_expiration")
entry = entity_registry.async_get("sensor.apk_expiration") entry = entity_registry.async_get("sensor.skoda_11zkz3_apk_expiration")
assert entry assert entry
assert state assert state
assert entry.unique_id == "11ZKZ3_apk_expiration" assert entry.unique_id == "11ZKZ3_apk_expiration"
assert state.state == "2022-01-04" assert state.state == "2022-01-04"
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "APK Expiration" assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Skoda 11ZKZ3 APK expiration"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DATE assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DATE
assert ATTR_ICON not in state.attributes assert ATTR_ICON not in state.attributes
assert ATTR_STATE_CLASS not in state.attributes assert ATTR_STATE_CLASS not in state.attributes
assert ATTR_UNIT_OF_MEASUREMENT not in state.attributes assert ATTR_UNIT_OF_MEASUREMENT not in state.attributes
state = hass.states.get("sensor.ascription_date") state = hass.states.get("sensor.skoda_11zkz3_ascription_date")
entry = entity_registry.async_get("sensor.ascription_date") entry = entity_registry.async_get("sensor.skoda_11zkz3_ascription_date")
assert entry assert entry
assert state assert state
assert entry.unique_id == "11ZKZ3_ascription_date" assert entry.unique_id == "11ZKZ3_ascription_date"
assert state.state == "2021-11-04" assert state.state == "2021-11-04"
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Ascription Date" assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Skoda 11ZKZ3 Ascription date"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DATE assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DATE
assert ATTR_ICON not in state.attributes assert ATTR_ICON not in state.attributes
assert ATTR_STATE_CLASS not in state.attributes assert ATTR_STATE_CLASS not in state.attributes
@ -50,7 +50,7 @@ async def test_vehicle_sensors(
assert device_entry assert device_entry
assert device_entry.identifiers == {(DOMAIN, "11ZKZ3")} assert device_entry.identifiers == {(DOMAIN, "11ZKZ3")}
assert device_entry.manufacturer == "Skoda" assert device_entry.manufacturer == "Skoda"
assert device_entry.name == "Skoda: 11ZKZ3" assert device_entry.name == "Skoda 11ZKZ3"
assert device_entry.entry_type is dr.DeviceEntryType.SERVICE assert device_entry.entry_type is dr.DeviceEntryType.SERVICE
assert device_entry.model == "Citigo" assert device_entry.model == "Citigo"
assert ( assert (