sfstar / hass-victron

Integration for Home Assistant to fetch data from the victron gx device via modbusTCP
Apache License 2.0
185 stars 29 forks source link

Data doesn't fetch/update if you constantly change a setting with automation #231

Open flip555 opened 2 months ago

flip555 commented 2 months ago

I have a CerboGX and interval is 30seconds, I have an automation to change max discharge depending different factors which runs every 5 seconds.

This number is usually the same so 2400, the automation runs every 5seconds and even though its the same number (both int and float) it updates and in debug log it says "Manually updated victron data"

This repeats forever, every 5 seconds, I guess resetting the 30second interval so the main function never runs to fetch the data.

I assume this would be the same for changing other settings not just numbers so I didn't do a pull request but for the number I added this to line 191 of number.py which fixed the non-updating sensors when spammed by automations - I guess some warning may be needed about too many requests but now mine updates both at the set interval or immediately after a number change.

await self.coordinator.async_request_refresh() 

Full Function:


async def async_set_native_value(self, value: float) -> None:
        """Update the current value."""
        #TODO convert float to int again with scale respected
        if value < 0:
            value = UINT16_MAX + value
        self.coordinator.write_register(unit=self.description.slave, address=self.description.address, value=self.coordinator.encode_scaling(value, self.description.native_unit_of_measurement, self.description.scale))
        await self.coordinator.async_update_local_entry(self.data_key, int(value))
        """Force update data after change."""
        await self.coordinator.async_request_refresh() 

EDIT: added the refresh to the async_update_local_entry function in cordinator.py instead and opened a PR https://github.com/sfstar/hass-victron/pull/232