Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Rova to has entity name #114303

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions homeassistant/components/rova/icons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"entity": {
"sensor": {
"bio": {
"default": "mdi:leaf"
},
"paper": {
"default": "mdi:file"
},
"plastic": {
"default": "mdi:recycle"
},
"residual": {
"default": "mdi:delete"
}
}
}
}
38 changes: 19 additions & 19 deletions homeassistant/components/rova/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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
Expand All @@ -27,28 +28,24 @@

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(
{
Expand Down Expand Up @@ -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,
Expand All @@ -136,10 +135,11 @@ def __init__(
"""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:
Expand Down
16 changes: 16 additions & 0 deletions homeassistant/components/rova/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,21 @@
"title": "The Rova YAML configuration import failed",
"description": "There was an error when trying to import your Rova YAML configuration.\n\nRova does not collect at this address.\n\nEnsure the imported configuration is correct and remove the Rova YAML configuration from your configuration.yaml file and continue to [set up the integration]({url}) manually."
}
},
"entity": {
"sensor": {
"bio": {
"name": "Bio"
},
"paper": {
"name": "Paper"
},
"plastic": {
"name": "Plastic"
},
"residual": {
"name": "Residual"
}
}
}
}
76 changes: 36 additions & 40 deletions tests/components/rova/snapshots/test_sensor.ambr
Original file line number Diff line number Diff line change
@@ -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({
}),
Expand All @@ -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>,
Expand All @@ -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({
}),
Expand All @@ -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>,
Expand All @@ -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({
}),
Expand All @@ -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>,
Expand All @@ -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({
}),
Expand All @@ -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>,
Expand All @@ -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>,
Expand Down