Simplify calls to pymodbus (#50717)
* simplify pymodbus_call. Do not call with a function object and a check attribute, call instead with CALL_TYPE*. Avoid if <type> call x else call y. Call async_pymodbus_call directly, instead of unpacking/packing. * Declare call type in __init__. * Modbus.py back to 100% test coverage.
This commit is contained in:
parent
7b18860dcd
commit
ff856a9bba
5 changed files with 92 additions and 34 deletions
|
@ -283,14 +283,9 @@ class ModbusRegisterSensor(RestoreEntity, SensorEntity):
|
|||
"""Update the state of the sensor."""
|
||||
# remark "now" is a dummy parameter to avoid problems with
|
||||
# async_track_time_interval
|
||||
if self._register_type == CALL_TYPE_REGISTER_INPUT:
|
||||
result = await self._hub.async_read_input_registers(
|
||||
self._slave, self._register, self._count
|
||||
)
|
||||
else:
|
||||
result = await self._hub.async_read_holding_registers(
|
||||
self._slave, self._register, self._count
|
||||
)
|
||||
result = await self._hub.async_pymodbus_call(
|
||||
self._slave, self._register, self._count, self._register_type
|
||||
)
|
||||
if result is None:
|
||||
self._available = False
|
||||
self.async_write_ha_state()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue