Commit Graph

189 Commits (e34fb4cfb9c2820cc7fa99b420356c2a963932fd)

Author SHA1 Message Date
jan iversen 646862ec96
Add array write to turn_on/off in modbus switch/fan/light (#52582) 2021-07-12 11:22:53 -07:00
jan iversen 5caf170c78
Correct Wrong "raise" in modbus validators. (#52924) 2021-07-12 11:06:31 -07:00
jan iversen 2ecfd74fa4
Add more data_types to modbus (#52423)
* Add more data_types.

* Use new struct when writing temperature.
2021-07-12 07:58:45 +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 f1303e02ff
Let climate use base_struct_schema. (#52154) 2021-06-28 22:21:31 -07:00
jan iversen c558c77413
Correct keyerror exception. (#52150) 2021-06-26 20:09:53 +02:00
jan iversen 1f4fdb50dc
Share struct validator between sensor and climate (#51935) 2021-06-23 11:03:17 -07:00
jan iversen bc329cb602
Convert if/elif chains to dicts in modbus (#51962) 2021-06-18 11:20:44 +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 77f6d1f5cb
Do not return an exception in modbus (#51829) 2021-06-14 10:56:24 +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 9e378d51af
Reduce modbus schemas and add delay to fan/light (#51664) 2021-06-11 09:22:47 +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 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 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
tkdrob 028a07d86f
Wrap up selectors (#50794)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2021-05-25 14:45:17 +02:00
jan iversen 8721675218
Use BaseSwitch class in modbus switch/fan/light (#51031) 2021-05-24 20:13:25 +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 c650deef98
Add base class for all modbus platforms (#50878)
* Add base for all platforms.

* Please pylint.
2021-05-20 16:56:11 +02:00
Maciej Bieniek e06a2a53c4
Add constructor return type in integrations L-N (#50888)
* Add constructor return type in integrations L-N

* Small fix
2021-05-20 13:06:44 +01:00
jan iversen b7fc537cd5
Remove non pymodbus_call from modbus.py. (#50813) 2021-05-19 11:39:53 +02:00
jan iversen 4c7fcae536
Small bug fixes in modbus due to async (#50812)
* Small bug fixes due to async.

* _available is true in turn_on/turn_off

* Remove double update.

* Set _available.
2021-05-19 10:13:48 +02:00
jan iversen ba827db8ec
Update remaining modbus platforms to use pymodbus_call (#50768) 2021-05-17 22:12:18 +02:00
jan iversen 6b34ba012c
Fix missing await in modbus platforms (followup on async PR) (#50710) 2021-05-17 14:20:51 +02:00
nikito7 0fac3ccebc
Change Modbus error message to bytes (#50725) 2021-05-17 14:12:17 +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 ad7be91b6a
Fix modbus blocking threads (#50619)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-05-15 19:54:17 +02:00
tkdrob a9660d5788
Add targets and selectors for services (L-M) (#50543) 2021-05-15 11:06:34 +02:00
jan iversen 19cdff10c3
Add "close_comm_on_error" to modbus configuration (#50583) 2021-05-14 10:54:23 +02:00
jan iversen dbf7430003
Bump pymodbus to v2.5.2 (#50582)
Solves a serial - rs-485 adapter issue.
2021-05-13 20:31:48 -07: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 552ca1c57b
Fix modbus switch problems (#50117) 2021-05-07 22:12:13 +02:00
jan iversen 2f89ba24b6
Cleanup modbus binary_sensor signature (#49809)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-05-05 00:29:18 +02:00
jan iversen f0ec9c38b0
Fix modbus typing (#49938)
Add changes needed to please mypy and follow the coding rules
of the project.
2021-05-03 22:45:21 +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 7ac05110ca
Catch non payload modbus messages (#49910) 2021-05-02 00:03:52 +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 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 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 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 914451d99c
Remove dead code in modbus sensor and 100% test coverage (#49634) 2021-04-25 15:25:02 +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 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 c14e525ac3
Update modbus state when sensor fails (#49481) 2021-04-20 14:54:20 +02:00
jan iversen a278ebd37b
Bump pymodbus version to 2.5.1 (#49401) 2021-04-20 10:43:14 +02:00
jan iversen 8acc3f0b03
Fix modbus switch "old style" config problem (#49352)
Fix that using CONF_HUB in switch, changed the hub for all
subsequent switches.
2021-04-19 10:35:32 -07:00
jan iversen eb9ba527d0
Add pymodbus exception handling and isolate pymodbus to class modbusHub (#49052) 2021-04-19 08:18:15 -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 0f90678e0e
Change HomeAssistantType -> HomeAssistant in modbus (#49400) 2021-04-18 22:13:32 -10: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
Franck Nijhof 055cdc64c0
Add support for IoT class in manifest (#46935) 2021-04-15 10:21:38 +02:00
Marc Mueller 1a38d2089d
Bump python-typing-update to v0.3.3 (#48992)
* Bump python-typing-update to 0.3.3
* Changes after update
2021-04-10 15:21:11 +02: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 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
Pim e2d3c0ea8f
Don't write 0 to next modbus register (#48378) 2021-03-29 12:45:44 +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
Erik Montnemery fdf97eaca3
Migrate integrations i-m to extend SensorEntity (#48213) 2021-03-22 19:59:03 +01:00
Marc Mueller 25a13d1554
Update typing 10 (#48071) 2021-03-18 13:07:04 +01:00
tkdrob a5a45f29e2
Cleanup unused loggers (#46510) 2021-02-14 13:46:58 +01:00
jan iversen 8418489345
Allow Modbus "old" config or discovery_info as configuration (#46445) 2021-02-12 16:33:18 +01:00
tkdrob c75e63dc95
Use core constants for modbus (#46388) 2021-02-11 07:58:16 -05:00
Vladimír Záhradník d518db1c95
Improve custom datatype parsing in Modbus sensor and climate (#42354) 2020-12-02 21:16:30 +01:00
Philip Allgaier 625bbe6238
Cleanup unused loggers (components A-M) (#41600) 2020-10-12 16:59:05 +02:00
Vladimír Záhradník 111afbb66f
Refactor Modbus switch to provide a base for other entities (#33551)
* Add Modbus light and fan entities

* Rework Fan and Light components to new config structure

* Fix Linter issue

* Rework Modbus switch initialization

* Properly update state on actuator methods

* Remove Fan and Light entity from this change. They will be merged separately

* Fix loading of the Switch platform

* Modbus switch - inherit from the SwitchEntity
2020-10-12 14:34:44 +02: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
Vladimír Záhradník ba84d0bf5c
Add custom data type support into Modbus climate (#32439) 2020-10-07 22:43:16 +02:00
Vladimír Záhradník 1d41f024cf
Add Modbus cover (#33642)
* Add Modbus cover

* Fix improper commands written for Modbus cover via coil

* Make changes per review comments

* Fix default hub not defined

Since support for multiple hubs was added, the default hub option
was not implemented correctly. Now I added necessary logic to make
it work. First hub in a list will be used as a default hub.

* Move Cover config under Modbus section

* Revert setting up a default hub alias

* Make hub mandatory for Cover

* Add default scan interval

* Read scan_interval from discovery info

* Fix linter error

* Use default scan interval from Cover platform

* Handle polling for Modbus cover directly inside entity

* Move covers under hub config

* Fix for review comment

* Call update() from Cover actuator methods

* Fix time validation
2020-09-26 11:11:51 -05:00
jan iversen c7f48e9ea3
Make modbus switch read_coil failure resistent (#40417)
* Make modbus switch read_coil failure resistent.

Make sure all return paths return true/false.

* Add comment how binary_sensor get its value (is_on).
2020-09-23 08:50:01 -05:00
jan iversen 9bd28306f6
Correct modbus switch to return correct coil (#40190) 2020-09-19 12:14:51 +02:00
Ville Skyttä b4bac0f7a0
Exception chaining and wrapping improvements (#39320)
* Remove unnecessary exception re-wraps

* Preserve exception chains on re-raise

We slap "from cause" to almost all possible cases here. In some cases it
could conceivably be better to do "from None" if we really want to hide
the cause. However those should be in the minority, and "from cause"
should be an improvement over the corresponding raise without a "from"
in all cases anyway.

The only case where we raise from None here is in plex, where the
exception for an original invalid SSL cert is not the root cause for
failure to validate a newly fetched one.

Follow local convention on exception variable names if there is a
consistent one, otherwise `err` to match with majority of codebase.

* Fix mistaken re-wrap in homematicip_cloud/hap.py

Missed the difference between HmipConnectionError and
HmipcConnectionError.

* Do not hide original error on plex new cert validation error

Original is not the cause for the new one, but showing old in the
traceback is useful nevertheless.
2020-08-28 13:50:32 +02:00
Franck Nijhof 4cf186a47e
Small collection of random styling tweaks, fixes and Pythonism (#35390) 2020-05-09 00:10:17 +02: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 1b3f9254bc
Add retry on empty modbus messages for serial protocol (#34678) 2020-05-06 14:08:43 +02:00
jan iversen 1b02410aa6
Change Modbus switch to use verify_register when defined (#34679) 2020-05-06 14:07:09 +02:00
Erik Montnemery 29bc93ea98
Rename ClimateDevice to ClimateEntity (#34591) 2020-04-25 18:04:03 +02:00
Erik Montnemery b022e08db9
Rename BinarySensorDevice to BinarySensorEntity (#34462)
* Rename BinarySensorDevice to BinarySensorEntity

* Tweak

* Move deprecation warning to __new__, add test

* Move deprecation warning back to __init__

* Move deprecation warning to __init_subclass
2020-04-23 21:57:07 +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 f8f8dddca7
Fix modbus sync/async issues (#34043)
* add pyserial to manifest

pymodbus is very developer oriented and assumes every developer
adapt the requierements.txt to his/hers needs.

Our requirements.txt is different it contains all posibilities allowing
user to later change configuration without having to install extra
packages.

As a consequence manifest.json needs to include the pyserial.

* modbus: make truly async client creation

Make hass call listen_once async.
Integrate content of start_modbus into async_setup.

Do not use the boiler plate create tcp client function from
pymodbus as it is sync, and also does not work well with asyncio,
instead call the init_<type> directly, since that is async.

* both component/modbus and component/serial uses pyserial-async
but with slighty different version requirements.

Combined the 2.

* Review 1

* Review 2

* Review

@staticmethod is no good, because the function uses class variables.

* Review

Pytest is sometimes a bit cryptic, lets hope this does it.
2020-04-12 19:55:03 +02:00