Add update of model and version for nibe (#83347)

This commit is contained in:
Joakim Plate
2022-12-06 20:20:55 +01:00
committed by GitHub
parent 8d1a70391e
commit 46669a1704

View File

@@ -11,7 +11,7 @@ from typing import Any, Generic, TypeVar
from nibe.coil import Coil
from nibe.connection import Connection
from nibe.connection.modbus import Modbus
from nibe.connection.nibegw import NibeGW
from nibe.connection.nibegw import NibeGW, ProductInfo
from nibe.exceptions import CoilNotFoundException, CoilReadException
from nibe.heatpump import HeatPump, Model, Series
@@ -99,14 +99,25 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
data[entry.entry_id] = coordinator
reg = dr.async_get(hass)
reg.async_get_or_create(
device_entry = reg.async_get_or_create(
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, entry.unique_id or entry.entry_id)},
manufacturer="NIBE Energy Systems",
model=heatpump.model.name,
name=heatpump.model.name,
)
def _on_product_info(product_info: ProductInfo):
reg.async_update_device(
device_id=device_entry.id,
model=product_info.model,
sw_version=str(product_info.firmware_version),
)
if isinstance(connection, NibeGW):
connection.subscribe(connection.PRODUCT_INFO_EVENT, _on_product_info)
else:
reg.async_update_device(device_id=device_entry.id, model=heatpump.model.name)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
# Trigger a refresh again now that all platforms have registered