Commit Graph

65 Commits (0476c7f9eef8aacbfbf6e332290ce2699ac27a57)

Author SHA1 Message Date
jan iversen 74e1600a84
Add fixture to handle mock restore state (#52198) 2021-06-28 22:21:04 -07:00
jan iversen 08b0ef7a5e
Use test fixture for configuration testing (#51803)
* Autospec mock_modbus and usei for configuration.

* Review comment.
2021-06-17 12:27:05 +02:00
jan iversen 3ba90776c0
Add autospec to modbus mock, in order to use getattr (#51813) 2021-06-17 10:57:20 +02:00
jan iversen 7ad91fdf71
Add swap to climate and change data_count -> count in modbus (#51668) 2021-06-16 12:11:23 +02:00
jan iversen 2a51587bc3
Remove reverse_order (replaced by generic swap) (#51665)
Remove reverse_order (replaced by generic swap).
2021-06-11 11:41:41 +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 5e067c2631
Allow unlimited scan_interval in modbus (#51471)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
2021-06-04 18:06:44 +02:00
jan iversen 10dccc6734
Move pymodbus test fixtures to test_init (#51244) 2021-06-02 00:00:44 +02:00
jan iversen 538a189168
Adjust modbus climate to use address/input_type (#51202) 2021-05-28 17:57:14 +02:00
jan iversen 00507539c1
Change Cover to use address/input_type (#51154)
* Change Cover to use address/input_type.

* Flake.
2021-05-28 13:23:44 +02:00
jan iversen e45196f9c9
Remove "old" config from modbus binary_sensor (#51117) 2021-05-28 12:06:46 +02:00
jan iversen 5afd16ef5d
Move modbus schema validators to validators.py (#51121) 2021-05-28 11:38:31 +02:00
jan iversen 47f016b340
Remove old config from cover, including tests (#51118)
* Remove old config and standardize new config.

* Add missing safeguard.
2021-05-28 11:29:37 +02:00
jan iversen 8d365e8bf5
After merge, review. (#51139) 2021-05-27 08:28:31 +02:00
Yuriy Sannikov 6391d75919
Refactor ModbusRegisterSensor class to get hub and configuration (#50234)
* refactor ModbusRegisterSensor to match the ModbusSwitch interface

* Please pylint, mypy etc.

* Remove PLATFORM.

Co-authored-by: jan Iversen <jancasacondor@gmail.com>
2021-05-26 19:28:14 +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 1546dbbf25
Add restore temperature to modbus climate (#50963)
* Add restore temperature to climate.

* please mypy.

* Review 2.
2021-05-24 14:03:44 +02:00
jan iversen be13a73db8
Allow manual scan and add delay in switch verify. (#50974) 2021-05-24 12:59:55 +02:00
jan iversen f55213d8b1
Update modbus cover to 100% coverage (#50996) 2021-05-23 10:18:35 -05:00
jan iversen 59ae78e5f0
Add restore_state to modbus binary_sensor (#50922)
* Add restore_state to binary_sensor.

* Update return value in State.
2021-05-22 13:38:05 +02:00
Vladimír Záhradník c979101a02
Add Modbus fan integration (#48558)
* Add Modbus fan entity

* Update to PR.

* Pylint.

Co-authored-by: jan Iversen <jancasacondor@gmail.com>
2021-05-21 09:56:47 +02:00
Vladimír Záhradník 80d172140f
Add Modbus light integration (#42120)
* Add  Modbus Light and add unit tests

* Update to original PR.

* Review comments.

* Review 2.

Co-authored-by: jan Iversen <jancasacondor@gmail.com>
2021-05-21 08:57:17 +02:00
jan iversen 892a2a0372
Push modbus switch to 100% test coverage (#50324)
push modbus switch to 100% test coverage.
2021-05-19 15:05:29 +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 224cc779c4
Correct Modbus platform cover restore state (#50421)
* Correct cover restore state.

* Change mock usage.

* Add states to convert.
2021-05-16 08:40:19 +02:00
jan iversen ca558545a1
Use mock_restore_state in testing of modbus sensor (#50455) 2021-05-15 21:39:41 +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 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 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
jan iversen 8adbc62a6e
Enable homeassistant.update_entity service for all modbus platforms (#49918)
* Rename _update() to update()

A platform neeed a function update(), even though
polling is false, this is due to the service:
homeassistant.update_entity, which calls update()

* Update test harnesss to script testing.

Test homeassistant.update_entity in all platforms.
This call calls update() in the platform to get
a new reading.

* Add reuse parameter.

* Move service call from helper to tests.

* Change run_service_update --> prepare_service_update.

* Remove entity_id parameter.
2021-05-02 10:41:36 +02:00
jan iversen aa8ce07e35
Start Modbus cover timer independent if there is a state to restore (#49919)
* Start timer independent if there is a state to restore.

* Update test cases, that now start working.
2021-04-30 22:36:55 +02:00
jan iversen 684ea9e49b
Restructure modbus switch, and solve read/write conflicts (#49386)
Remove old style configuration from switch.
- The old style configuration allowed a number of illegal
  configurations, instead of adding if...log. in setup we
  only support the new configuration style.

Add new/changed configuration switch.

Removed verify_state and cleaned configuration to avoid possible
illegal configurations.
2021-04-30 16:47:18 +02:00
jan iversen 760caeed85
Complete modbus device response tests (#49633)
* Prepare test harness for new pymodbus return types.

Use pytest.fixture to mock pymodbus.
Use pytest.fixture to load modbus using mocked pymodbus
Add test of Exception/IllegalResponse/ExceptionResponse from pymodbus.

* Modbus.py is back at 100% test coverage.

* Added assert mock.called.

* add mock reset.
2021-04-29 18:06:56 +02:00
jan iversen e5e215353d
Add swap byte/word/byteword option to modbus sensor (#49719)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-04-27 10:49:41 +02:00
jan iversen 677d8e9a89
Add restore last state test to modbus sensor (#49721) 2021-04-27 00:20:50 +02:00
jan iversen f67c0ce8bb
Secure 100% test coverage for modbus, binary_sensor and sensor (#49521)
* Secure 100% test coverage for modbus/binary_sensor.

* Test that class constructor is called.
2021-04-22 11:54:40 +02:00
jan iversen d24b3e0a3c
Test pymodbus (#49053) 2021-04-20 11:25:37 -07:00
Vladimír Záhradník 05755c27f2
Log an error if modbus Cover is not initialized correctly (#48829) 2021-04-19 16:52:08 +02:00
jan iversen ea9641f980
Apply Precision/Scale/Offset to struct in modbus sensor (#48544)
The single values in struct are corrected with presicion, scale and offset,
just as it is done with single values.
2021-04-16 22:33:58 +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 cee43b0670
Add modbus CONF_VERIFY_STATE to new switch config (#48632)
Missed CONF_VERIFY_STATE in new switch config, when
copying from old switch config.
2021-04-03 11:00:06 +02:00
jan iversen 0d7168a667
Remove duplicate test case in modbus switch (#48636) 2021-04-02 22:09:27 +02:00
jan iversen 64d5dd1f6b
Remove if/else from modbus test cases (#48514) 2021-03-31 11:20:14 +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 855bd653b4
Update modbus test harness (#44892)
* Update test harness to allow discovery_info testing.

This is a needed update, before the whole config is converted
to the new structure, because it allows test of both the old
and new configuration style.

The following changes have been made:
- Combine test functions into a single base_test.
- Prepare for new mock by combining the 2 common test functions into one.
- Change mock to be only modbusHub
- Do not replace whole modbus class, but only the class that
  connects to pymodbus (modbusHub). This allows test of modbus
  configurations and not only component configurations, and is needed
  when testing discovery activated platform.
- Add test of climate.
  Warning this is merely test of discovery,
  the real cover tests still needs to be added.
- Add test of cover.
  Warning this is merely test of discovery,
  the real cover tests still needs to be added.

* Update comment for old config

* Do not use hass.data, but instead patch pymodbus library.

* Add test of configuration (old/new way as available).

* Move assert to test function.

Make assert more understandable by removing it from the helper.

add base_config_test (check just calls base_test) to make it clear if
test is wanted or just controlling the config.

* use setup_component to load Modbus since it is an integration.

* Optimized flow in test helper.
2021-02-14 17:40:30 +01:00
tkdrob c75e63dc95
Use core constants for modbus (#46388) 2021-02-11 07:58:16 -05:00
Franck Nijhof 65cf2fcb6f
Drop asynctest (#44746) 2021-01-01 22:31:56 +01:00
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