mirror of
https://github.com/home-assistant/core
synced 2024-08-02 23:40:32 +02: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
|
||||
|
||||
|
||||
class PVOutputDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
class PVOutputDataUpdateCoordinator(DataUpdateCoordinator[Status]):
|
||||
"""The PVOutput Data Update Coordinator."""
|
||||
|
||||
config_entry: ConfigEntry
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
|
||||
from pvo import Status
|
||||
from pvo import Status, System
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
@ -29,12 +29,10 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import (
|
||||
ATTR_EFFICIENCY,
|
||||
@ -47,6 +45,7 @@ from .const import (
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
)
|
||||
from .coordinator import PVOutputDataUpdateCoordinator
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
@ -162,12 +161,15 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""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(
|
||||
PVOutputSensorEntity(
|
||||
coordinator=coordinator,
|
||||
description=description,
|
||||
system_id=entry.data[CONF_SYSTEM_ID],
|
||||
system=system,
|
||||
)
|
||||
for description in SENSORS
|
||||
)
|
||||
@ -176,20 +178,28 @@ async def async_setup_entry(
|
||||
class PVOutputSensorEntity(CoordinatorEntity, SensorEntity):
|
||||
"""Representation of a PVOutput sensor."""
|
||||
|
||||
coordinator: DataUpdateCoordinator[Status]
|
||||
coordinator: PVOutputDataUpdateCoordinator
|
||||
entity_description: PVOutputSensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
coordinator: DataUpdateCoordinator,
|
||||
coordinator: PVOutputDataUpdateCoordinator,
|
||||
description: PVOutputSensorEntityDescription,
|
||||
system_id: str,
|
||||
system: System,
|
||||
) -> None:
|
||||
"""Initialize a PVOutput sensor."""
|
||||
super().__init__(coordinator=coordinator)
|
||||
self.entity_description = description
|
||||
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
|
||||
def native_value(self) -> int | float | None:
|
||||
|
Loading…
Reference in New Issue
Block a user