Add device info to ISS (#96469)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
pull/96872/head
Joost Lekkerkerker 2023-07-18 20:57:41 +02:00 committed by GitHub
parent 8675bc6554
commit c94c7fae1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View File

@ -7,9 +7,7 @@ from homeassistant.const import CONF_SHOW_ON_MAP
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from .const import DOMAIN
DEFAULT_NAME = "ISS"
from .const import DEFAULT_NAME, DOMAIN
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):

View File

@ -1,3 +1,5 @@
"""Constants for iss."""
DOMAIN = "iss"
DEFAULT_NAME = "ISS"

View File

@ -8,6 +8,8 @@ from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, CONF_SHOW_ON_MAP
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
@ -15,7 +17,7 @@ from homeassistant.helpers.update_coordinator import (
)
from . import IssData
from .const import DOMAIN
from .const import DEFAULT_NAME, DOMAIN
_LOGGER = logging.getLogger(__name__)
@ -28,23 +30,32 @@ async def async_setup_entry(
"""Set up the sensor platform."""
coordinator: DataUpdateCoordinator[IssData] = hass.data[DOMAIN]
name = entry.title
show_on_map = entry.options.get(CONF_SHOW_ON_MAP, False)
async_add_entities([IssSensor(coordinator, name, show_on_map)])
async_add_entities([IssSensor(coordinator, entry, show_on_map)])
class IssSensor(CoordinatorEntity[DataUpdateCoordinator[IssData]], SensorEntity):
"""Implementation of the ISS sensor."""
_attr_has_entity_name = True
_attr_name = None
def __init__(
self, coordinator: DataUpdateCoordinator[IssData], name: str, show: bool
self,
coordinator: DataUpdateCoordinator[IssData],
entry: ConfigEntry,
show: bool,
) -> None:
"""Initialize the sensor."""
super().__init__(coordinator)
self._state = None
self._attr_name = name
self._attr_unique_id = f"{entry.entry_id}_people"
self._show_on_map = show
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, entry.entry_id)},
name=DEFAULT_NAME,
entry_type=DeviceEntryType.SERVICE,
)
@property
def native_value(self) -> int: