Add device info to Solax (#65244)
This commit is contained in:
parent
9610fa5979
commit
202ee0cd3d
2 changed files with 15 additions and 2 deletions
|
@ -2,3 +2,5 @@
|
|||
|
||||
|
||||
DOMAIN = "solax"
|
||||
|
||||
MANUFACTURER = "SolaX Power"
|
||||
|
|
|
@ -19,11 +19,12 @@ from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT, TEMP_CELSIUS
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from .const import DOMAIN
|
||||
from .const import DOMAIN, MANUFACTURER
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -46,6 +47,7 @@ async def async_setup_entry(
|
|||
api = hass.data[DOMAIN][entry.entry_id]
|
||||
resp = await api.get_data()
|
||||
serial = resp.serial_number
|
||||
version = resp.version
|
||||
endpoint = RealTimeDataEndpoint(hass, api)
|
||||
hass.async_add_job(endpoint.async_refresh)
|
||||
async_track_time_interval(hass, endpoint.async_refresh, SCAN_INTERVAL)
|
||||
|
@ -72,7 +74,9 @@ async def async_setup_entry(
|
|||
device_class = SensorDeviceClass.BATTERY
|
||||
state_class = SensorStateClass.MEASUREMENT
|
||||
uid = f"{serial}-{idx}"
|
||||
devices.append(Inverter(uid, serial, sensor, unit, state_class, device_class))
|
||||
devices.append(
|
||||
Inverter(uid, serial, version, sensor, unit, state_class, device_class)
|
||||
)
|
||||
endpoint.sensors = devices
|
||||
async_add_entities(devices)
|
||||
|
||||
|
@ -140,6 +144,7 @@ class Inverter(SensorEntity):
|
|||
self,
|
||||
uid,
|
||||
serial,
|
||||
version,
|
||||
key,
|
||||
unit,
|
||||
state_class=None,
|
||||
|
@ -151,6 +156,12 @@ class Inverter(SensorEntity):
|
|||
self._attr_native_unit_of_measurement = unit
|
||||
self._attr_state_class = state_class
|
||||
self._attr_device_class = device_class
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, serial)},
|
||||
manufacturer=MANUFACTURER,
|
||||
name=f"Solax {serial}",
|
||||
sw_version=version,
|
||||
)
|
||||
self.key = key
|
||||
self.value = None
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue