Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update coordinator and deye mirco #356

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions custom_components/solarman/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,45 @@

class InverterCoordinator(DataUpdateCoordinator[dict[str, Any]]):
def __init__(self, hass: HomeAssistant, inverter: Inverter):
super().__init__(hass, _LOGGER, name = inverter.config.name, update_interval = TIMINGS_UPDATE_INTERVAL, always_update = False)
super().__init__(
Copy link
Owner

@davidrapan davidrapan Jan 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, don't reformat code like this. The line is not that long and I'm not really a fan of using just narrow columns of the code. 😉

hass,
_LOGGER,
name=inverter.config.name,
update_interval=TIMINGS_UPDATE_INTERVAL,
always_update=False,
)
self.inverter = inverter
self._counter = 0
self._last_successful_data: dict[str, Any] | None = None
self._is_offline_logged = False

async def _async_setup(self) -> None:
try:
return await self.inverter.load()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await self.inverter.load()
except Exception as e:
if isinstance(e, TimeoutError):
raise
raise UpdateFailed(e) from e

async def _async_update_data(self) -> dict[str, Any]:
try:
return await self.inverter.get(int(self._counter * self._update_interval_seconds))
data = await self.inverter.get(int(self._counter * self._update_interval_seconds))
self._last_successful_data = data
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already talked about this, did you forgot? self._last_successful_data is already stored in self.data. So this additional caching is completely unnecessary.
https://github.com/home-assistant/core/blob/5a7b6cd7a05773c9216313439c23c78980dc04a7/homeassistant/helpers/update_coordinator.py#L98
Before attempting any adjustments, familiarize yourself with the Home Assistant code.

self._is_offline_logged = False
return data
except Exception as e:
self._counter = 0

if not self._is_offline_logged:
_LOGGER.warning("Error retrieving data. Use last known data.")
self._is_offline_logged = True

if self._last_successful_data is not None:
return self._last_successful_data
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On top of that as we already discussed this, data are cached not just here in the data attribute but w/ sensors itself and are ONLY HIDDEN by making them "unavailable" so this whole contraption is highly unnecessary.


if isinstance(e, TimeoutError):
raise

raise UpdateFailed(e) from e
finally:
if self.last_update_success:
Expand Down
29 changes: 26 additions & 3 deletions custom_components/solarman/inverter_definitions/deye_micro.yaml
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already discussed this
#87 (comment)
and you did not get back to me...

I want just single sensor for this so let's make it work in current format by bit shifting, okay?

I want to avoid this 1, 2, 3, ... nonsense. 😉

Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ parameters:
- key: "default"
value: "Error"

- name: "Device Fault"
- name: "Device Fault 1"
class: "enum"
rule: 3
registers: [0x0067, 0x0068, 0x0069, 0x006A]
registers: [0x0067]
icon: "mdi:message-alert-outline"
lookup:
- key: 0x0000
Expand Down Expand Up @@ -242,11 +242,34 @@ parameters:
value: "Arc Fault Reservation"
- key: 0x2000
value: "Grid Current Sample Abnormality"
- key: 0x2030000
- key: "default"
value: "Error"

- name: "Device Fault 2"
class: "enum"
rule: 3
registers: [0x0068]
icon: "mdi:message-alert-outline"
lookup:
- key: 0x0000
value: "OK"
- key: 0x191
value: "Grid phase failure or No Relay Connection"
- key: "default"
value: "Error"

- name: "Device Debug 1"
class: "enum"
rule: 3
registers: [0x0069]
icon: "mdi:message-alert-outline"

- name: "Device Debug 2"
class: "enum"
rule: 3
registers: [0x006A]
icon: "mdi:message-alert-outline"

- group: PV
items:
- name: PV Power
Expand Down
2 changes: 1 addition & 1 deletion custom_components/solarman/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/davidrapan/ha-solarman/issues",
"requirements": ["propcache", "aiofiles", "pyyaml", "umodbus"],
"version": "24.12.22"
"version": "25.01.17"
}