Add lazy_error_count to modbus (#54412)

* Add lazy_error_count.

* Use -=

* Review comments.
This commit is contained in:
jan iversen 2021-08-21 15:49:50 +02:00 committed by GitHub
parent 51434c5faa
commit 33f660118f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 47 additions and 1 deletions

View file

@ -64,10 +64,15 @@ class ModbusRegisterSensor(BaseStructPlatform, RestoreEntity, SensorEntity):
self._slave, self._address, self._count, self._input_type
)
if result is None:
if self._lazy_errors:
self._lazy_errors -= 1
return
self._lazy_errors = self._lazy_error_count
self._attr_available = False
self.async_write_ha_state()
return
self._attr_native_value = self.unpack_structure_result(result.registers)
self._lazy_errors = self._lazy_error_count
self._attr_available = True
self.async_write_ha_state()