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
|
@ -151,12 +151,9 @@ class ModbusBinarySensor(BinarySensorEntity):
|
|||
"""Update the state of the sensor."""
|
||||
# remark "now" is a dummy parameter to avoid problems with
|
||||
# async_track_time_interval
|
||||
if self._input_type == CALL_TYPE_COIL:
|
||||
result = await self._hub.async_read_coils(self._slave, self._address, 1)
|
||||
else:
|
||||
result = await self._hub.async_read_discrete_inputs(
|
||||
self._slave, self._address, 1
|
||||
)
|
||||
result = await self._hub.async_pymodbus_call(
|
||||
self._slave, self._address, 1, self._input_type
|
||||
)
|
||||
if result is None:
|
||||
self._available = False
|
||||
self.async_write_ha_state()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue