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"
|
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.core import HomeAssistant
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
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.event import async_track_time_interval
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN, MANUFACTURER
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ async def async_setup_entry(
|
||||||
api = hass.data[DOMAIN][entry.entry_id]
|
api = hass.data[DOMAIN][entry.entry_id]
|
||||||
resp = await api.get_data()
|
resp = await api.get_data()
|
||||||
serial = resp.serial_number
|
serial = resp.serial_number
|
||||||
|
version = resp.version
|
||||||
endpoint = RealTimeDataEndpoint(hass, api)
|
endpoint = RealTimeDataEndpoint(hass, api)
|
||||||
hass.async_add_job(endpoint.async_refresh)
|
hass.async_add_job(endpoint.async_refresh)
|
||||||
async_track_time_interval(hass, endpoint.async_refresh, SCAN_INTERVAL)
|
async_track_time_interval(hass, endpoint.async_refresh, SCAN_INTERVAL)
|
||||||
|
@ -72,7 +74,9 @@ async def async_setup_entry(
|
||||||
device_class = SensorDeviceClass.BATTERY
|
device_class = SensorDeviceClass.BATTERY
|
||||||
state_class = SensorStateClass.MEASUREMENT
|
state_class = SensorStateClass.MEASUREMENT
|
||||||
uid = f"{serial}-{idx}"
|
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
|
endpoint.sensors = devices
|
||||||
async_add_entities(devices)
|
async_add_entities(devices)
|
||||||
|
|
||||||
|
@ -140,6 +144,7 @@ class Inverter(SensorEntity):
|
||||||
self,
|
self,
|
||||||
uid,
|
uid,
|
||||||
serial,
|
serial,
|
||||||
|
version,
|
||||||
key,
|
key,
|
||||||
unit,
|
unit,
|
||||||
state_class=None,
|
state_class=None,
|
||||||
|
@ -151,6 +156,12 @@ class Inverter(SensorEntity):
|
||||||
self._attr_native_unit_of_measurement = unit
|
self._attr_native_unit_of_measurement = unit
|
||||||
self._attr_state_class = state_class
|
self._attr_state_class = state_class
|
||||||
self._attr_device_class = device_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.key = key
|
||||||
self.value = None
|
self.value = None
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue