Commit Graph

42 Commits (e34fb4cfb9c2820cc7fa99b420356c2a963932fd)

Author SHA1 Message Date
jan iversen 6a39119ccc
Streamline modbus before 100% coverage. (#57478) 2021-10-11 13:26:36 -05:00
Marc Mueller d51487f82a
Import Callable from collections.abc (3) (#56777) 2021-09-29 16:19:06 +02:00
jan iversen f3ad4ca0cc
Strictly type modbus.py. (#56375) 2021-09-20 18:47:05 +02:00
jan iversen a84e86ff13
Strictly type modbus base_platform.py (#56343) 2021-09-20 14:59:30 +02:00
jan iversen aaa62dadec
Add service to stop/restart modbus (#55599)
* Add service to stop/restart modbus.

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-09-14 09:42:50 +02:00
jan iversen f91cc21bbd
Solve modbus shutdown racing condition (#55373) 2021-08-28 23:04:33 +02:00
jan iversen 7ac72ebf38
Add modbus name to log_error (#55336) 2021-08-27 09:26:57 -07:00
jan iversen 2d5176eee9
Change entity_timers to be a local variable. (#55258)
Ensure outstanding pymodbus calls are handled before closing.
2021-08-26 15:23:00 +02:00
jan iversen d4064e7044
Cancel entity timers. (#55141) 2021-08-25 14:49:37 +02:00
jan iversen bafbbc6563
Adjust modbus constants names (#54792)
* Follow up.
2021-08-18 12:56:54 +02:00
jan iversen e8aa280d7f
Add modbus get_hub (#54277)
* Add dict with hubs.

* Update flexit to use get_hub.

* Remove executor_task for close.
2021-08-08 22:48:33 +02:00
jan iversen 2232915ea8
Add parameter to delay sending of requests in modbus (#54203) 2021-08-07 21:10:08 -07:00
jan iversen 3d52bfc8f6
Simplify DATA_TYPE -> struct conversion. (#53805) 2021-07-31 23:17:23 +02:00
jan iversen 78ef02f4d9
Allow pymodbus to reconnect in running system (not startup) (#53020)
Allow pymodbus to reconnect (not during startup).
2021-07-19 13:01:50 +02:00
jan iversen c360d6009c
copy() --> deepcopy(). (#52794) 2021-07-14 11:00:16 +02:00
jan iversen fe1f7ba316
Add check for _client existence in modbus (#52719) 2021-07-08 11:58:51 +02:00
jan iversen 1cb298948f
Fix MODBUS connection type rtuovertcp does not connect (#52505)
* Correct host -> framer.

* Use function pointer
2021-07-05 11:45:50 +02:00
jan iversen bc329cb602
Convert if/elif chains to dicts in modbus (#51962) 2021-06-18 11:20:44 +02:00
jan iversen 77f6d1f5cb
Do not return an exception in modbus (#51829) 2021-06-14 10:56:24 +02:00
jan iversen 50001684aa
Add retries/retry_on_empty configuration parameters to Modbus (#51412)
* Add retries/retry_on_empty configuration parameters.

* Please review comment.
2021-06-06 09:13:50 +02:00
jan iversen 59b5f94569
Add fix delay after send/request to allow RS485 adapter to switch in modbus (#51417) 2021-06-05 14:41:32 +02:00
jan iversen b8afb7dcfe
Check initial connect() worked in modbus (#51470)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
Co-authored-by: Franck Nijhof <git@frenck.dev>
2021-06-05 14:39:09 +02:00
jan iversen c74e65ac2d
Streamline modbus test_init (#50990)
* Streamline test_init.

* Review comments.

* Remove hub name.
2021-05-24 14:53:54 +02:00
jan iversen b7fc537cd5
Remove non pymodbus_call from modbus.py. (#50813) 2021-05-19 11:39:53 +02:00
jan iversen ba827db8ec
Update remaining modbus platforms to use pymodbus_call (#50768) 2021-05-17 22:12:18 +02:00
jan iversen ff856a9bba
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.
2021-05-17 11:20:12 +02:00
jan iversen ad7be91b6a
Fix modbus blocking threads (#50619)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-05-15 19:54:17 +02:00
jan iversen 19cdff10c3
Add "close_comm_on_error" to modbus configuration (#50583) 2021-05-14 10:54:23 +02:00
jan iversen 70b09ed9a1
Handle relation between scan_interval and pymodbus timeout in modbus (#50363)
* Control scan_interval compared to pymodbus timeout.

add MINIMUM_SCAN_INTERVAL=5 seconds and validata with Voluptous.
Keep modbus.py 100% coverage.

* Please pylint.

* Review comments.

* pylint.
2021-05-10 19:28:38 +02:00
jan iversen ec08256ff0
Do not use async_* in a modbus sync function (#50343) 2021-05-09 19:50:23 +02:00
jan iversen 29eb31e9da
Add configurable delay between connect and first request in modbus (#50124)
* Activate startup delay.

* Add removal of call_later if HA is stopped.

This is unlikely to happen, but just security measure.

* Removing timing interval.

async_fire_time_changed() needs to be called twice, first time the delay is
ended and second time update() is executed.

* Variable naming.
2021-05-08 13:28:35 +02:00
Vladimír Záhradník e0de6752af
Fix incorrect attribute checks in Modbus hub (#50241) 2021-05-08 13:26:31 +02:00
jan iversen 7ac05110ca
Catch non payload modbus messages (#49910) 2021-05-02 00:03:52 +02:00
jan iversen 5b6d2edb48
Catch missing/unavailable response from modbus (#49632)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-04-29 15:59:17 +02:00
jan iversen 33e8553d92
Fix frontend freeze due to modbus device not responding (#49651)
Changing the timeout from package default, secures SENDING will
timeout, and after 3 retries break off.

Remark: this commit is tested with pymodbus v2.5.1 the old version
v2.3.0 have several problems in this area.
self._value = await self.async_get_last_state()

pymodbus v2.5.1 is active on DEV (bumped in an earlier PR).
2021-04-25 23:11:01 +02:00
jan iversen c9bdc9609c
Do not close non existing clients in modbus (#49489)
* Only close if _client is present.

* Remove del.
2021-04-21 11:46:40 +02:00
jan iversen eb9ba527d0
Add pymodbus exception handling and isolate pymodbus to class modbusHub (#49052) 2021-04-19 08:18:15 -07:00
jan iversen d5ef382fd5
Add modbus write coils (#48676)
* Add missing function in class.

write_coils was missing.

* Remove dead code.

The HA configuration secures that CONF_TYPE only contains legal values,
so having an empty assert to catch unknown values is dead code.

An empty assert is not informative.
2021-04-04 21:53:52 +02:00
jan iversen 2511e1f229
Remove modbus duplicate strings (#48654)
* Reuse HA constants for serial configuration.

Reusing HA consts reduces the need for translation.

Sort/group constants in const.

* Change const name ATTR_* to CONF_*

* Correct wrong import

* ATTR_* for service and CONF_* for schemas.

* Revert change to service call.

* Rename CONF_TEMPERATURE -> ATTR_TEMPERATURE

Avoid possible division problem in set_temperature.
2021-04-04 14:02:47 +02:00
jan iversen 23fae255ff
Make modbus WRITE_COIL use write_coils in case of an array (#48633)
* WRITE_COIL uses write_coils in case of an array.

WRITE_REGISTER uses write_register/write_registers depending
on whether value is singular or an array.

WRITE_COIL is modified to be similar and uses
write_coil/write_coils depending on whether value is singular or an
array.

* Update SERVICE_WRITE_COIL to allow list.
2021-04-03 13:15:01 +02:00
jan iversen ffdfc521b9
Allow discovery configuration of modbus platforms (#46591)
* Change modbus configuration to new style.

The old (frozen) configuration is still supported, but when detected a big
warning is issued that it will soon be removed. This allows users to change
their configuration at their pace.

Clean configuration SCHEMAs and move common modbus parts
to MODBUS_SCHEMA (renamed from BASE_SCHEMA).

Add BASE_COMPONENT_SCHEMA to ensure common configuration of components.
All component define e.g. NAME, move these to a common schema.
change components (binary_sensor, sensor, switch) to new config

Add test set for modbus itself (old config and discovery_info).
Add test of devices discovery_info configuration

* Update discovery_info configuration for binary_sensor.

* Update discovery_info configuration for sensor.

* Update discovery_info configuration for switch.

* Review comments.

* update due to change in core

* flake8 problem.

* Correct log message.

* add should_poll property.

* Fix polling for Modbus binary sensor

* Fix polling for Modbus sensor

* Fix polling for Modbus switch

* Fix switch.

* Fix pytest errors.

* Update homeassistant/components/modbus/binary_sensor.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/modbus/binary_sensor.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/modbus/modbus.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/modbus/sensor.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/modbus/sensor.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/modbus/sensor.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/modbus/switch.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/modbus/switch.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/modbus/switch.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* ToogleEntity -> SwitchEntity and add abastract

* Update homeassistant/components/modbus/switch.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update tests/components/modbus/test_init.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* removed if/else in test.

* Remove other if.

Co-authored-by: Vladimir Zahradnik <vladimir@zahradnik.io>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-03-27 22:48:06 +01:00
jan iversen 8418489345
Allow Modbus "old" config or discovery_info as configuration (#46445) 2021-02-12 16:33:18 +01:00