1 """DataUpdateCoordinator for the aurora_abb_powerone integration."""
6 from aurorapy.client
import AuroraError, AuroraSerialClient, AuroraTimeoutError
7 from serial
import SerialException
13 from .const
import DOMAIN, SCAN_INTERVAL
15 _LOGGER = logging.getLogger(__name__)
18 type AuroraAbbConfigEntry = ConfigEntry[AuroraAbbDataUpdateCoordinator]
22 """Class to manage fetching AuroraAbbPowerone data."""
24 def __init__(self, hass: HomeAssistant, comport: str, address: int) ->
None:
25 """Initialize the data update coordinator."""
28 self.
clientclient = AuroraSerialClient(address, comport, parity=
"N", timeout=1)
29 super().
__init__(hass, _LOGGER, name=DOMAIN, update_interval=SCAN_INTERVAL)
32 """Fetch new state data for the sensors.
34 This is the only function that should fetch new data for Home Assistant.
36 data: dict[str, float] = {}
41 self.
clientclient.connect()
44 grid_voltage = self.
clientclient.measure(1,
True)
45 grid_current = self.
clientclient.measure(2,
True)
46 power_watts = self.
clientclient.measure(3,
True)
47 frequency = self.
clientclient.measure(4)
48 i_leak_dcdc = self.
clientclient.measure(6)
49 i_leak_inverter = self.
clientclient.measure(7)
50 temperature_c = self.
clientclient.measure(21)
51 r_iso = self.
clientclient.measure(30)
52 energy_wh = self.
clientclient.cumulated_energy(5)
53 [alarm, *_] = self.
clientclient.alarms()
54 except AuroraTimeoutError:
56 _LOGGER.debug(
"No response from inverter (could be dark)")
58 except (SerialException, AuroraError)
as error:
64 "Exception: %s occurred, %d retries remaining",
70 data[
"grid_voltage"] = round(grid_voltage, 1)
71 data[
"grid_current"] = round(grid_current, 1)
72 data[
"instantaneouspower"] = round(power_watts, 1)
73 data[
"grid_frequency"] = round(frequency, 1)
74 data[
"i_leak_dcdc"] = i_leak_dcdc
75 data[
"i_leak_inverter"] = i_leak_inverter
76 data[
"temp"] = round(temperature_c, 1)
78 data[
"totalenergy"] = round(energy_wh / 1000, 2)
85 _LOGGER.warning(
"Communication with %s back online", self.
namename)
88 "Communication with %s lost",
91 if self.
clientclient.serline.isOpen():
97 """Update inverter data in the executor."""
98 return await self.
hasshass.async_add_executor_job(self.
_update_data_update_data)
dict[str, float] _async_update_data(self)
None __init__(self, HomeAssistant hass, str comport, int address)
dict[str, float] _update_data(self)