Migrate Rova to has entity name (#114303)

This commit is contained in:
Joost Lekkerkerker 2024-03-27 16:20:51 +01:00 committed by GitHub
parent 4d27f4be51
commit 6289082dab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 89 additions and 59 deletions

View File

@ -0,0 +1,18 @@
{
"entity": {
"sensor": {
"bio": {
"default": "mdi:leaf"
},
"paper": {
"default": "mdi:file"
},
"plastic": {
"default": "mdi:recycle"
},
"residual": {
"default": "mdi:delete"
}
}
}
}

View File

@ -17,6 +17,7 @@ from homeassistant.const import CONF_MONITORED_CONDITIONS, CONF_NAME
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -27,28 +28,24 @@ from .coordinator import RovaCoordinator
ISSUE_PLACEHOLDER = {"url": "/config/integrations/dashboard/add?domain=rova"}
SENSOR_TYPES = {
"bio": SensorEntityDescription(
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="gft",
name="bio",
icon="mdi:recycle",
translation_key="bio",
),
"paper": SensorEntityDescription(
SensorEntityDescription(
key="papier",
name="paper",
icon="mdi:recycle",
translation_key="paper",
),
"plastic": SensorEntityDescription(
SensorEntityDescription(
key="pmd",
name="plastic",
icon="mdi:recycle",
translation_key="plastic",
),
"residual": SensorEntityDescription(
SensorEntityDescription(
key="restafval",
name="residual",
icon="mdi:recycle",
translation_key="residual",
),
}
)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
@ -119,14 +116,16 @@ async def async_setup_entry(
unique_id = entry.unique_id
async_add_entities(
RovaSensor(unique_id, description, coordinator)
for key, description in SENSOR_TYPES.items()
RovaSensor(unique_id, description, coordinator) for description in SENSOR_TYPES
)
class RovaSensor(CoordinatorEntity[RovaCoordinator], SensorEntity):
"""Representation of a Rova sensor."""
_attr_device_class = SensorDeviceClass.TIMESTAMP
_attr_has_entity_name = True
def __init__(
self,
unique_id: str,
@ -136,10 +135,11 @@ class RovaSensor(CoordinatorEntity[RovaCoordinator], SensorEntity):
"""Initialize the sensor."""
super().__init__(coordinator)
self.entity_description = description
self._attr_name = f"{unique_id}_{description.key}"
self._attr_unique_id = f"{unique_id}_{description.key}"
self._attr_device_class = SensorDeviceClass.TIMESTAMP
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, unique_id)},
entry_type=DeviceEntryType.SERVICE,
)
@property
def native_value(self) -> datetime | None:

View File

@ -33,5 +33,21 @@
"title": "Rova does not collect at this address anymore",
"description": "Rova does not collect at {zip_code} anymore.\n\nPlease remove the integration."
}
},
"entity": {
"sensor": {
"bio": {
"name": "Bio"
},
"paper": {
"name": "Paper"
},
"plastic": {
"name": "Plastic"
},
"residual": {
"name": "Residual"
}
}
}
}

View File

@ -1,5 +1,5 @@
# serializer version: 1
# name: test_all_entities[sensor.8381be13_gft-entry]
# name: test_all_entities[sensor.8381be_13_bio-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
@ -11,8 +11,8 @@
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.8381be13_gft',
'has_entity_name': False,
'entity_id': 'sensor.8381be_13_bio',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
@ -22,32 +22,31 @@
'options': dict({
}),
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
'original_icon': 'mdi:recycle',
'original_name': '8381BE13_gft',
'original_icon': None,
'original_name': 'Bio',
'platform': 'rova',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'translation_key': 'bio',
'unique_id': '8381BE13_gft',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[sensor.8381be13_gft-state]
# name: test_all_entities[sensor.8381be_13_bio-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'timestamp',
'friendly_name': '8381BE13_gft',
'icon': 'mdi:recycle',
'friendly_name': '8381BE 13 Bio',
}),
'context': <ANY>,
'entity_id': 'sensor.8381be13_gft',
'entity_id': 'sensor.8381be_13_bio',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '2024-02-20T23:00:00+00:00',
})
# ---
# name: test_all_entities[sensor.8381be13_papier-entry]
# name: test_all_entities[sensor.8381be_13_paper-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
@ -59,8 +58,8 @@
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.8381be13_papier',
'has_entity_name': False,
'entity_id': 'sensor.8381be_13_paper',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
@ -70,32 +69,31 @@
'options': dict({
}),
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
'original_icon': 'mdi:recycle',
'original_name': '8381BE13_papier',
'original_icon': None,
'original_name': 'Paper',
'platform': 'rova',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'translation_key': 'paper',
'unique_id': '8381BE13_papier',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[sensor.8381be13_papier-state]
# name: test_all_entities[sensor.8381be_13_paper-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'timestamp',
'friendly_name': '8381BE13_papier',
'icon': 'mdi:recycle',
'friendly_name': '8381BE 13 Paper',
}),
'context': <ANY>,
'entity_id': 'sensor.8381be13_papier',
'entity_id': 'sensor.8381be_13_paper',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '2024-03-05T23:00:00+00:00',
})
# ---
# name: test_all_entities[sensor.8381be13_pmd-entry]
# name: test_all_entities[sensor.8381be_13_plastic-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
@ -107,8 +105,8 @@
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.8381be13_pmd',
'has_entity_name': False,
'entity_id': 'sensor.8381be_13_plastic',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
@ -118,32 +116,31 @@
'options': dict({
}),
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
'original_icon': 'mdi:recycle',
'original_name': '8381BE13_pmd',
'original_icon': None,
'original_name': 'Plastic',
'platform': 'rova',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'translation_key': 'plastic',
'unique_id': '8381BE13_pmd',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[sensor.8381be13_pmd-state]
# name: test_all_entities[sensor.8381be_13_plastic-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'timestamp',
'friendly_name': '8381BE13_pmd',
'icon': 'mdi:recycle',
'friendly_name': '8381BE 13 Plastic',
}),
'context': <ANY>,
'entity_id': 'sensor.8381be13_pmd',
'entity_id': 'sensor.8381be_13_plastic',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '2024-03-11T23:00:00+00:00',
})
# ---
# name: test_all_entities[sensor.8381be13_restafval-entry]
# name: test_all_entities[sensor.8381be_13_residual-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
@ -155,8 +152,8 @@
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.8381be13_restafval',
'has_entity_name': False,
'entity_id': 'sensor.8381be_13_residual',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
@ -166,25 +163,24 @@
'options': dict({
}),
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
'original_icon': 'mdi:recycle',
'original_name': '8381BE13_restafval',
'original_icon': None,
'original_name': 'Residual',
'platform': 'rova',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'translation_key': 'residual',
'unique_id': '8381BE13_restafval',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[sensor.8381be13_restafval-state]
# name: test_all_entities[sensor.8381be_13_residual-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'timestamp',
'friendly_name': '8381BE13_restafval',
'icon': 'mdi:recycle',
'friendly_name': '8381BE 13 Residual',
}),
'context': <ANY>,
'entity_id': 'sensor.8381be13_restafval',
'entity_id': 'sensor.8381be_13_residual',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,