Add device info to ISS (#96469)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
8675bc6554
commit
c94c7fae1b
3 changed files with 20 additions and 9 deletions
|
@ -7,9 +7,7 @@ from homeassistant.const import CONF_SHOW_ON_MAP
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DEFAULT_NAME, DOMAIN
|
||||||
|
|
||||||
DEFAULT_NAME = "ISS"
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
"""Constants for iss."""
|
"""Constants for iss."""
|
||||||
|
|
||||||
DOMAIN = "iss"
|
DOMAIN = "iss"
|
||||||
|
|
||||||
|
DEFAULT_NAME = "ISS"
|
||||||
|
|
|
@ -8,6 +8,8 @@ from homeassistant.components.sensor import SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, CONF_SHOW_ON_MAP
|
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, CONF_SHOW_ON_MAP
|
||||||
from homeassistant.core import HomeAssistant
|
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.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
CoordinatorEntity,
|
CoordinatorEntity,
|
||||||
|
@ -15,7 +17,7 @@ from homeassistant.helpers.update_coordinator import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import IssData
|
from . import IssData
|
||||||
from .const import DOMAIN
|
from .const import DEFAULT_NAME, DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -28,23 +30,32 @@ async def async_setup_entry(
|
||||||
"""Set up the sensor platform."""
|
"""Set up the sensor platform."""
|
||||||
coordinator: DataUpdateCoordinator[IssData] = hass.data[DOMAIN]
|
coordinator: DataUpdateCoordinator[IssData] = hass.data[DOMAIN]
|
||||||
|
|
||||||
name = entry.title
|
|
||||||
show_on_map = entry.options.get(CONF_SHOW_ON_MAP, False)
|
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):
|
class IssSensor(CoordinatorEntity[DataUpdateCoordinator[IssData]], SensorEntity):
|
||||||
"""Implementation of the ISS sensor."""
|
"""Implementation of the ISS sensor."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
_attr_name = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, coordinator: DataUpdateCoordinator[IssData], name: str, show: bool
|
self,
|
||||||
|
coordinator: DataUpdateCoordinator[IssData],
|
||||||
|
entry: ConfigEntry,
|
||||||
|
show: bool,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._state = None
|
self._attr_unique_id = f"{entry.entry_id}_people"
|
||||||
self._attr_name = name
|
|
||||||
self._show_on_map = show
|
self._show_on_map = show
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, entry.entry_id)},
|
||||||
|
name=DEFAULT_NAME,
|
||||||
|
entry_type=DeviceEntryType.SERVICE,
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> int:
|
def native_value(self) -> int:
|
||||||
|
|
Loading…
Add table
Reference in a new issue