Migrate GDACS to has entity name (#104733)
This commit is contained in:
parent
2f0846bd87
commit
6ac9a1d1f2
2 changed files with 13 additions and 5 deletions
|
@ -7,6 +7,7 @@ import logging
|
|||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
@ -44,12 +45,14 @@ class GdacsSensor(SensorEntity):
|
|||
_attr_should_poll = False
|
||||
_attr_icon = DEFAULT_ICON
|
||||
_attr_native_unit_of_measurement = DEFAULT_UNIT_OF_MEASUREMENT
|
||||
_attr_has_entity_name = True
|
||||
_attr_name = None
|
||||
|
||||
def __init__(self, config_entry: ConfigEntry, manager) -> None:
|
||||
"""Initialize entity."""
|
||||
assert config_entry.unique_id
|
||||
self._config_entry_id = config_entry.entry_id
|
||||
self._attr_unique_id = config_entry.unique_id
|
||||
self._attr_name = f"GDACS ({config_entry.title})"
|
||||
self._manager = manager
|
||||
self._status = None
|
||||
self._last_update = None
|
||||
|
@ -60,6 +63,11 @@ class GdacsSensor(SensorEntity):
|
|||
self._updated = None
|
||||
self._removed = None
|
||||
self._remove_signal_status: Callable[[], None] | None = None
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, config_entry.unique_id)},
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
manufacturer="GDACS",
|
||||
)
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Call when entity is added to hass."""
|
||||
|
|
|
@ -72,10 +72,10 @@ async def test_setup(hass: HomeAssistant) -> None:
|
|||
== 4
|
||||
)
|
||||
|
||||
state = hass.states.get("sensor.gdacs_32_87336_117_22743")
|
||||
state = hass.states.get("sensor.32_87336_117_22743")
|
||||
assert state is not None
|
||||
assert int(state.state) == 3
|
||||
assert state.name == "GDACS (32.87336, -117.22743)"
|
||||
assert state.name == "32.87336, -117.22743"
|
||||
attributes = state.attributes
|
||||
assert attributes[ATTR_STATUS] == "OK"
|
||||
assert attributes[ATTR_CREATED] == 3
|
||||
|
@ -96,7 +96,7 @@ async def test_setup(hass: HomeAssistant) -> None:
|
|||
== 4
|
||||
)
|
||||
|
||||
state = hass.states.get("sensor.gdacs_32_87336_117_22743")
|
||||
state = hass.states.get("sensor.32_87336_117_22743")
|
||||
attributes = state.attributes
|
||||
assert attributes[ATTR_CREATED] == 1
|
||||
assert attributes[ATTR_UPDATED] == 2
|
||||
|
@ -125,6 +125,6 @@ async def test_setup(hass: HomeAssistant) -> None:
|
|||
== 1
|
||||
)
|
||||
|
||||
state = hass.states.get("sensor.gdacs_32_87336_117_22743")
|
||||
state = hass.states.get("sensor.32_87336_117_22743")
|
||||
attributes = state.attributes
|
||||
assert attributes[ATTR_REMOVED] == 3
|
||||
|
|
Loading…
Add table
Reference in a new issue