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 geniushub to has entity name #126986

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions homeassistant/components/geniushub/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,14 @@ async def async_setup_entry(
class GeniusBinarySensor(GeniusDevice, BinarySensorEntity):
"""Representation of a Genius Hub binary_sensor."""

_attr_name = None

def __init__(self, broker, device, state_attr) -> None:
"""Initialize the binary sensor."""
super().__init__(broker, device)

self._state_attr = state_attr

if device.type[:21] == "Dual Channel Receiver":
self._attr_name = f"{device.type[:21]} {device.id}"
else:
self._attr_name = f"{device.type} {device.id}"

@property
def is_on(self) -> bool:
"""Return the status of the sensor."""
Expand Down
25 changes: 20 additions & 5 deletions homeassistant/components/geniushub/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any

from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity
import homeassistant.util.dt as dt_util
Expand All @@ -25,6 +26,7 @@
class GeniusEntity(Entity):
"""Base for all Genius Hub entities."""

_attr_has_entity_name = True
_attr_should_poll = False

def __init__(self) -> None:
Expand Down Expand Up @@ -56,6 +58,16 @@
self._unique_id = f"{broker.hub_uid}_device_{device.id}"
self._last_comms: datetime | None = None
self._state_attr = None
device_name = device.type
if device_name[:21] == "Dual Channel Receiver":
device_name = "Dual Channel Receiver"

Check warning on line 63 in homeassistant/components/geniushub/entity.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/geniushub/entity.py#L63

Added line #L63 was not covered by tests
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, f"{broker.hub_uid}_{device.id}")},
model=device.type,
name=f"{device_name} {device.id}",
suggested_area=device.data["assignedZones"][0]["name"],
via_device=(DOMAIN, broker.hub_uid),
)

@property
def extra_state_attributes(self) -> dict[str, Any]:
Expand Down Expand Up @@ -86,12 +98,20 @@
class GeniusZone(GeniusEntity):
"""Base for all Genius Hub zones."""

_attr_name = None

def __init__(self, broker, zone) -> None:
"""Initialize the Zone."""
super().__init__()

self._zone = zone
self._unique_id = f"{broker.hub_uid}_zone_{zone.id}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, f"{broker.hub_uid}_{zone.id}")},
name=zone.name,
suggested_area=zone.name,
via_device=(DOMAIN, broker.hub_uid),
)

async def _refresh(self, payload: dict | None = None) -> None:
"""Process any signals."""
Expand All @@ -118,11 +138,6 @@

await self._zone.set_mode(mode)

@property
def name(self) -> str:
"""Return the name of the climate device."""
return self._zone.name

@property
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the device state attributes."""
Expand Down
11 changes: 7 additions & 4 deletions homeassistant/components/geniushub/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.const import PERCENTAGE
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
import homeassistant.util.dt as dt_util

from . import GeniusHubConfigEntry
from . import DOMAIN, GeniusHubConfigEntry
from .entity import GeniusDevice, GeniusEntity

GH_STATE_ATTR = "batteryLevel"
Expand Down Expand Up @@ -54,8 +55,6 @@ def __init__(self, broker, device, state_attr) -> None:

self._state_attr = state_attr

self._attr_name = f"{device.type} {device.id}"

@property
def icon(self) -> str:
"""Return the icon of the sensor."""
Expand Down Expand Up @@ -98,9 +97,13 @@ def __init__(self, broker, level) -> None:
self._hub = broker.client
self._unique_id = f"{broker.hub_uid}_{GH_LEVEL_MAPPING[level]}"

self._attr_name = f"GeniusHub {GH_LEVEL_MAPPING[level]}"
self._attr_translation_key = level
self._level = level
self._issues: list = []
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, broker.hub_uid)},
name="GeniusHub",
)

@property
def native_value(self) -> int:
Expand Down
14 changes: 13 additions & 1 deletion homeassistant/components/geniushub/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,19 @@
"unknown": "[%key:common::config_flow::error::unknown%]"
}
},

"entity": {
"sensor": {
"error": {
"name": "Errors"
},
"warning": {
"name": "Warnings"
},
"information": {
"name": "Information"
}
}
},
"services": {
"set_zone_mode": {
"name": "Set zone mode",
Expand Down
4 changes: 2 additions & 2 deletions tests/components/geniushub/snapshots/test_binary_sensor.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'domain': 'binary_sensor',
'entity_category': None,
'entity_id': 'binary_sensor.single_channel_receiver_22',
'has_entity_name': False,
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
Expand All @@ -23,7 +23,7 @@
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Single Channel Receiver 22',
'original_name': None,
'platform': 'geniushub',
'previous_unique_id': None,
'supported_features': 0,
Expand Down
28 changes: 14 additions & 14 deletions tests/components/geniushub/snapshots/test_climate.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
'domain': 'climate',
'entity_category': None,
'entity_id': 'climate.bedroom',
'has_entity_name': False,
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
Expand All @@ -33,7 +33,7 @@
}),
'original_device_class': None,
'original_icon': 'mdi:radiator',
'original_name': 'Bedroom',
'original_name': None,
'platform': 'geniushub',
'previous_unique_id': None,
'supported_features': <ClimateEntityFeature: 401>,
Expand Down Expand Up @@ -102,7 +102,7 @@
'domain': 'climate',
'entity_category': None,
'entity_id': 'climate.ensuite',
'has_entity_name': False,
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
Expand All @@ -113,7 +113,7 @@
}),
'original_device_class': None,
'original_icon': 'mdi:radiator',
'original_name': 'Ensuite',
'original_name': None,
'platform': 'geniushub',
'previous_unique_id': None,
'supported_features': <ClimateEntityFeature: 401>,
Expand Down Expand Up @@ -184,7 +184,7 @@
'domain': 'climate',
'entity_category': None,
'entity_id': 'climate.guest_room',
'has_entity_name': False,
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
Expand All @@ -195,7 +195,7 @@
}),
'original_device_class': None,
'original_icon': 'mdi:radiator',
'original_name': 'Guest room',
'original_name': None,
'platform': 'geniushub',
'previous_unique_id': None,
'supported_features': <ClimateEntityFeature: 401>,
Expand Down Expand Up @@ -266,7 +266,7 @@
'domain': 'climate',
'entity_category': None,
'entity_id': 'climate.hall',
'has_entity_name': False,
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
Expand All @@ -277,7 +277,7 @@
}),
'original_device_class': None,
'original_icon': 'mdi:radiator',
'original_name': 'Hall',
'original_name': None,
'platform': 'geniushub',
'previous_unique_id': None,
'supported_features': <ClimateEntityFeature: 401>,
Expand Down Expand Up @@ -348,7 +348,7 @@
'domain': 'climate',
'entity_category': None,
'entity_id': 'climate.kitchen',
'has_entity_name': False,
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
Expand All @@ -359,7 +359,7 @@
}),
'original_device_class': None,
'original_icon': 'mdi:radiator',
'original_name': 'Kitchen',
'original_name': None,
'platform': 'geniushub',
'previous_unique_id': None,
'supported_features': <ClimateEntityFeature: 401>,
Expand Down Expand Up @@ -429,7 +429,7 @@
'domain': 'climate',
'entity_category': None,
'entity_id': 'climate.lounge',
'has_entity_name': False,
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
Expand All @@ -440,7 +440,7 @@
}),
'original_device_class': None,
'original_icon': 'mdi:radiator',
'original_name': 'Lounge',
'original_name': None,
'platform': 'geniushub',
'previous_unique_id': None,
'supported_features': <ClimateEntityFeature: 401>,
Expand Down Expand Up @@ -509,7 +509,7 @@
'domain': 'climate',
'entity_category': None,
'entity_id': 'climate.study',
'has_entity_name': False,
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
Expand All @@ -520,7 +520,7 @@
}),
'original_device_class': None,
'original_icon': 'mdi:radiator',
'original_name': 'Study',
'original_name': None,
'platform': 'geniushub',
'previous_unique_id': None,
'supported_features': <ClimateEntityFeature: 401>,
Expand Down
65 changes: 65 additions & 0 deletions tests/components/geniushub/snapshots/test_init.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# serializer version: 1
# name: test_device_info
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': None,
'connections': set({
}),
'disabled_by': None,
'entry_type': None,
'hw_version': None,
'id': <ANY>,
'identifiers': set({
tuple(
'geniushub',
'01J71MQF0EC62D620DGYNG2R8H',
),
}),
'is_new': False,
'labels': set({
}),
'manufacturer': None,
'model': None,
'model_id': None,
'name': 'GeniusHub',
'name_by_user': None,
'primary_config_entry': <ANY>,
'serial_number': None,
'suggested_area': None,
'sw_version': None,
'via_device_id': None,
})
# ---
# name: test_device_info.1
DeviceRegistryEntrySnapshot({
'area_id': 'study',
'config_entries': <ANY>,
'configuration_url': None,
'connections': set({
}),
'disabled_by': None,
'entry_type': None,
'hw_version': None,
'id': <ANY>,
'identifiers': set({
tuple(
'geniushub',
'01J71MQF0EC62D620DGYNG2R8H_30',
),
}),
'is_new': False,
'labels': set({
}),
'manufacturer': None,
'model': None,
'model_id': None,
'name': 'Study',
'name_by_user': None,
'primary_config_entry': <ANY>,
'serial_number': None,
'suggested_area': 'Study',
'sw_version': None,
'via_device_id': None,
})
# ---
Loading