Commit Graph

117 Commits (f6600bbc209130cffee3b8b115e8309488eafc73)

Author SHA1 Message Date
jan iversen 55cdec8c4e
Add test for register configuration for modbus switch (#42604)
* check for false config in modbus tests.

add call to pytest.fail() if device cannot be defined.

* correct bit error in register read.

Only LSB is to be considered for checking ON/OFF

* Add register tests for modbus switch.

Copy the coil tests to work for register tests.

* allow test coverage to control switch.py

With both register and coil test the coverage is a log higher than 50%

* Correct minor bug in handling of register in modbus switch

* Add state_on/state_off test for modbus switch

* restore modbus switch exclusion from coverage

switch file coverage is only at 72%, ideally we want either 80%+ coverage on the file or 90%+ on the component itself which is only about 83% currently with this file included. this is so we keep the overall project coverage in 90%+.

Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-11-08 10:42:45 -06:00
Paulus Schoutsen 440570244d
Don't swallow all errors when checking for config validator platform (#42058) 2020-10-19 17:09:57 +02:00
Philip Allgaier dde6305549
Cleanup unused loggers (components N-Z + tests) (#41982) 2020-10-16 21:24:08 -05:00
jan iversen 4d9ff13384
Fix bool registers in modbus integration (#41506)
When a register is of type bool modbus returns a whole byte, but ONLY the
lowest bit determine true/false.
2020-10-08 23:52:41 +02:00
jan iversen 9f3701bd32
Change modbus tests to use pytest.mark.parametrize (#41486) 2020-10-08 15:47:59 +02:00
jan iversen 639c864a76
Add test coverage for modbus switch (coil part) (#40696)
* Prepare test code for complex devices.

push entity_id to conftest, to make it common for all devices.

Add device to base_setup.

* Add test coverage for modbus switch (coil part).

* Update .coveragerc

* Update .coveragerc

Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-10-01 11:00:26 -05:00
jan iversen 0ca19133d9
Add tests for modbus binary sensor (#40367)
* Add test coverage of binary sensor.

Update conftest to be generic.

* Pass total config structure to run_base_test.

Simple devices like sensor/switch do only have one entry in the
dict array, whereas e.g. switch have multiple entries.

* Use STATE_ON / _OFF for binary_sensor test.

* Update coveragerc

Only exclude files that uses a third party library.

* Remove modbus/* from coveragerc

* Remove modbus from .coveragerc

* Update .coveragerc

Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-09-27 20:00:44 -05:00
Paulus Schoutsen 276f3afb00
Do async_setup_platform in background (#36244)
Co-authored-by: J. Nick Koston <nick@koston.org>
2020-05-31 22:18:30 -07:00
Brad Keifer 4663845ebc
Add modbus sensor string data_type (#35269)
* modbus sensor: string data_type

Adds support for a string data_type. This allows the reading of holding registers that contain ascii string data

* Add modbus sensor string data_type #35269

Fingers crossed that I am putting these file in the correct location this time

* Delete const.py

* Delete sensor.py

* Add files via upload

* modbus sensor - add string support. Upload from local dev environment

* fix executable stauts

* fix flake8 failure
2020-05-08 11:30:05 +02:00
jan iversen 8277ebcbe1
Rollback modbus to version 0.107.7 keep new functionality (#34287)
* Rollback modbus to version 0.107.7

Update manifest to not use async.

Rollback entities to sync version.

Keep newer modifications apart from async.

Rollback __init__ to sync version but keep the new functionality.

add async sub directory

Adding the current (not working) version in a sub directory,
to allow easy sharing with a few alfa testers.

The async version are to be updated to use the serial/tcp already
available instead of the flaky pymodbus version. pymodbus is still
needed to encode/decode the messagess.

Update test cases to reflect sync implementation, but
keep the new functionality like e.g. conftest.py.

* do not publish async version

The async version will be made available in a forked repo, until
it is ready to replace the production code.
2020-04-17 09:55:57 +02:00
jan iversen 9535dd87b0
Rename domain import in modbus (#33906) 2020-04-09 22:15:20 +02:00
jan iversen b3286a4a01
Fix Modbus review comments (#33755)
* update common test for modbus integration

* remove log messages from modbus setup function.

* Make global method local

* Change parameter name to snake_case
2020-04-07 16:56:48 +02:00
jan iversen 738ef38ddc
Modbus: isolate common test functions (#33447)
Since all entity test functions are going to use
the modbus class, isolate the common parts in
conftest.py, and thereby make it simpler to write
additional test cases.

cleaned up test_modbus_sensor.py while splitting the code.
2020-04-05 19:09:20 -04:00
jan iversen dd3cd95954
Modbus patch, to allow communication with "slow" equipment using tcp (#32557)
* modbus: bumb pymodbus version to 2.3.0

pymodbus version 1.5.2 did not support asyncio, and in general
the async handling have been improved a lot in version 2.3.0.

updated core/requirement*txt

* updated core/CODEOWNERS

committing result of 'python3 -m script.hassfest'.

* modbus: change core connection to async

change setup() --> async_setup and update() --> async_update()

Use async_setup_platform() to complete the async connection to core.

listen for EVENT_HOMEASSISTANT_START happens in async_setup()
so it needs to be async_listen.

But listen for EVENT_HOMEASSISTANT_STOP happens in start_modbus()
which is a sync. function so it continues to be listen().

* modbus: move setup of pymodbus into modbushub

setup of pymodbus is logically connected to the class modbushub,
therefore move it into the class.

Delay construction of pymodbus client until event
EVENT_HOMEASSISTANT_START arrives.

* modbus: use pymodbus async library

convert pymodbus calls to refer to the async library.

Remark: connect() is no longer needed, it is done when constructing
the client. There are also automatic reconnect.

* modbus: use async update for read/write

Use async functions for read/write from pymodbus.

change thread.Lock() to asyncio.Lock()

* Modbus: patch for slow tcp equipment

When connecting, via Modbus-TCP, so some equipment (like the
huawei sun2000 inverter), they need time to prepare the protocol.

Solution is to add a asyncio.sleep(x) after the connect() and before
sending the first message.

Add optional parameter "delay" to Modbus configuration.
Default is 0, which means do not execute asyncio.sleep().

* Modbus: silence pylint false positive

pylint does not accept that a class construction __new__
can return a tuple.

* Modbus: move constants to const.py

Create const.py with constants only used in
the modbus integration.

Duplicate entries are removed, but NOT any entry that would
lead to a configuration change.

Some entries were the same but with different names, in this
case renaming is done.

Also correct the tests.

* Modbus: move connection error handling to ModbusHub

Connection error handling depends on the hub, not the
entity, therefore it is logical to have the handling in
ModbusHub.

All pymodbus call are added to 2 generic functions (read/write)
in order not to duplicate the error handling code.

Added property "available" to signal if the hub is connected.

* Modbus: CI cleanup

Solve CI problems.

* Modbus: remove close of client

close() no longer exist in the pymodbus library, use
del client instead.

* Modbus: correct review comments

Adjust code based on review comments.

* Modbus: remove twister dependency

Pymodbus in asyncio mode do not use twister but still throws a
warning if twister is not installed, this warning goes into
homeassistant.log and can thus cause confusion among users.

However installing twister just to avoid the warning is not
the best solution, therefore removing dependency on twister.

* Modbus: review, remove comments.

remove commented out code.
2020-03-29 12:39:30 -05:00
Vladimír Záhradník 32cd58e03d
Modbus remove unnecessary get calls (#31966) 2020-02-18 19:41:12 -08:00
Bas Nijholt 710680d604 use isort to sort imports for components starting with 'm' (#29772) 2019-12-09 18:50:40 +05:30
Tomi Lehto b79f1336be Fix 64-bit modbus sensor register reads (#25672)
* Fix 64-bit modbus sensor register reads

When reading four 16-bit modbus registers as a sensor value,
slave output is stored first as 64-bit integer, but before returning
that value is converted to double precision floating point. This
causes rounding errors for integer values bigger than 2^53.

After this change floating point conversion is done only if user
has configured scaling or offset using floating points.

* Formatting

* Review fixes
2019-08-09 17:03:12 -07:00