mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Add device info to PVOutput (#62951)
This commit is contained in:
parent
4fe62a251d
commit
8b59b3baf4
@ -13,7 +13,7 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
|||||||
from .const import CONF_SYSTEM_ID, DOMAIN, LOGGER, SCAN_INTERVAL
|
from .const import CONF_SYSTEM_ID, DOMAIN, LOGGER, SCAN_INTERVAL
|
||||||
|
|
||||||
|
|
||||||
class PVOutputDataUpdateCoordinator(DataUpdateCoordinator):
|
class PVOutputDataUpdateCoordinator(DataUpdateCoordinator[Status]):
|
||||||
"""The PVOutput Data Update Coordinator."""
|
"""The PVOutput Data Update Coordinator."""
|
||||||
|
|
||||||
config_entry: ConfigEntry
|
config_entry: ConfigEntry
|
||||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from pvo import Status
|
from pvo import Status, System
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
@ -29,12 +29,10 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
CoordinatorEntity,
|
|
||||||
DataUpdateCoordinator,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_EFFICIENCY,
|
ATTR_EFFICIENCY,
|
||||||
@ -47,6 +45,7 @@ from .const import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
)
|
)
|
||||||
|
from .coordinator import PVOutputDataUpdateCoordinator
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
@ -162,12 +161,15 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up a PVOutput sensors based on a config entry."""
|
"""Set up a PVOutput sensors based on a config entry."""
|
||||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator: PVOutputDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
system = await coordinator.pvoutput.system()
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
PVOutputSensorEntity(
|
PVOutputSensorEntity(
|
||||||
coordinator=coordinator,
|
coordinator=coordinator,
|
||||||
description=description,
|
description=description,
|
||||||
system_id=entry.data[CONF_SYSTEM_ID],
|
system_id=entry.data[CONF_SYSTEM_ID],
|
||||||
|
system=system,
|
||||||
)
|
)
|
||||||
for description in SENSORS
|
for description in SENSORS
|
||||||
)
|
)
|
||||||
@ -176,20 +178,28 @@ async def async_setup_entry(
|
|||||||
class PVOutputSensorEntity(CoordinatorEntity, SensorEntity):
|
class PVOutputSensorEntity(CoordinatorEntity, SensorEntity):
|
||||||
"""Representation of a PVOutput sensor."""
|
"""Representation of a PVOutput sensor."""
|
||||||
|
|
||||||
coordinator: DataUpdateCoordinator[Status]
|
coordinator: PVOutputDataUpdateCoordinator
|
||||||
entity_description: PVOutputSensorEntityDescription
|
entity_description: PVOutputSensorEntityDescription
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
coordinator: DataUpdateCoordinator,
|
coordinator: PVOutputDataUpdateCoordinator,
|
||||||
description: PVOutputSensorEntityDescription,
|
description: PVOutputSensorEntityDescription,
|
||||||
system_id: str,
|
system_id: str,
|
||||||
|
system: System,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize a PVOutput sensor."""
|
"""Initialize a PVOutput sensor."""
|
||||||
super().__init__(coordinator=coordinator)
|
super().__init__(coordinator=coordinator)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_unique_id = f"{system_id}_{description.key}"
|
self._attr_unique_id = f"{system_id}_{description.key}"
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
configuration_url=f"https://pvoutput.org/list.jsp?sid={system_id}",
|
||||||
|
identifiers={(DOMAIN, system_id)},
|
||||||
|
manufacturer="PVOutput",
|
||||||
|
model=system.inverter_brand,
|
||||||
|
name=system.system_name,
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> int | float | None:
|
def native_value(self) -> int | float | None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user