Skip to content

Commit

Permalink
Add support for whole apsystems ez1 series (#123356)
Browse files Browse the repository at this point in the history
* Add support for whole apsystems ez1 series by configuring the max_output at setup to match the value by the inverter

* Check Max output for apsystems on startup, not setup

* Move max output check into coordinator

* Raise UpdateFailed on error in apsystems
  • Loading branch information
mawoka-myblock authored Aug 19, 2024
1 parent f2d41bd commit e3ab30a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion homeassistant/components/apsystems/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from APsystemsEZ1 import APsystemsEZ1M, ReturnAlarmInfo, ReturnOutputData

from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .const import LOGGER

Expand All @@ -34,6 +34,13 @@ def __init__(self, hass: HomeAssistant, api: APsystemsEZ1M) -> None:
)
self.api = api

async def _async_setup(self) -> None:
try:
max_power = (await self.api.get_device_info()).maxPower
except (ConnectionError, TimeoutError):
raise UpdateFailed from None
self.api.max_power = max_power

async def _async_update_data(self) -> ApSystemsSensorData:
output_data = await self.api.get_output_data()
alarm_info = await self.api.get_alarm_info()
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/apsystems/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ async def async_setup_entry(
class ApSystemsMaxOutputNumber(ApSystemsEntity, NumberEntity):
"""Base sensor to be used with description."""

_attr_native_max_value = 800
_attr_native_min_value = 30
_attr_native_step = 1
_attr_device_class = NumberDeviceClass.POWER
Expand All @@ -42,6 +41,7 @@ def __init__(
super().__init__(data)
self._api = data.coordinator.api
self._attr_unique_id = f"{data.device_id}_output_limit"
self._attr_native_max_value = data.coordinator.api.max_power

async def async_update(self) -> None:
"""Set the state with the value fetched from the inverter."""
Expand Down

0 comments on commit e3ab30a

Please sign in to comment.