Skip to content

Commit cf2ba36

Browse files
committed
Only load rated information on boot
1 parent e9b339a commit cf2ba36

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

‎custom_components/axpert_inverter/coordinator.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def __init__(self, hass: HomeAssistant, inverter: AxpertInverter, entry: ConfigE
3434
self.firmware_version = None
3535
self.model_id = None
3636
self.model_name = None
37+
self.rated_information = None
3738

3839
async def _async_update_data(self):
3940
"""Update data via library."""
@@ -56,6 +57,9 @@ def _io_update(self):
5657
if not self.model_name:
5758
self.model_name = self.inverter.get_model_name()
5859

60+
if not self.rated_information:
61+
self.rated_information = self.inverter.get_rated_information()
62+
5963
data = self.inverter.get_general_status()
6064
if not data:
6165
raise UpdateFailed("Received empty data from QPIGS")
@@ -70,9 +74,8 @@ def _io_update(self):
7074
if mode:
7175
data["mode"] = mode
7276

73-
# Get QPIRI for selectors
74-
qpiri_data = self.inverter.get_rated_information()
75-
if qpiri_data:
76-
data.update(qpiri_data)
77+
# Add rated information (QPIRI) for selectors
78+
if self.rated_information:
79+
data.update(self.rated_information)
7780

7881
return data

‎custom_components/axpert_inverter/number.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ async def _async_set_value_generic(self, func, value):
4747
self._attr_available = False
4848
self.async_write_ha_state()
4949
else:
50-
# Refresh data
50+
# Invalidate cache and refresh data
51+
self.coordinator.rated_information = None
5152
await self.coordinator.async_request_refresh()
5253

5354
class AxpertMaxChargingCurrent(AxpertNumberEntity):

‎custom_components/axpert_inverter/select.py‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ async def async_select_option(self, option: str) -> None:
5858

5959
if success:
6060
self._attr_current_option = option
61+
self.coordinator.rated_information = None
6162
self.async_write_ha_state()
63+
await self.coordinator.async_request_refresh()
6264
_LOGGER.info(f"Set AC Input Range to {option}")
6365
else:
6466
_LOGGER.error(f"Failed to set AC Input Range to {option}")
@@ -116,9 +118,8 @@ async def async_select_option(self, option: str) -> None:
116118
self.coordinator.inverter.set_output_source_priority, val
117119
)
118120
if success:
119-
# Optimistically update? Or wait for poll.
120-
# Wait for poll is safer but slower.
121-
pass
121+
self.coordinator.rated_information = None
122+
await self.coordinator.async_request_refresh()
122123

123124
class AxpertChargerPrioritySelect(AxpertEntity, SelectEntity):
124125
"""Select entity for Charger Source Priority."""
@@ -155,7 +156,8 @@ async def async_select_option(self, option: str) -> None:
155156
self.coordinator.inverter.set_charger_source_priority, val
156157
)
157158
if success:
158-
pass
159+
self.coordinator.rated_information = None
160+
await self.coordinator.async_request_refresh()
159161

160162

161163
class AxpertBatteryTypeSelect(AxpertEntity, SelectEntity):
@@ -191,7 +193,10 @@ async def async_select_option(self, option: str) -> None:
191193
success = await self.hass.async_add_executor_job(
192194
self.coordinator.inverter.set_battery_type, val
193195
)
194-
if not success:
196+
if success:
197+
self.coordinator.rated_information = None
198+
await self.coordinator.async_request_refresh()
199+
else:
195200
_LOGGER.warning(f"Failed to set Battery Type to {option}")
196201
self._attr_available = False
197202
self.async_write_ha_state()

0 commit comments

Comments
 (0)