Commit Graph

78 Commits (28a909c46339dfc3f7b4c4a21ce343aa582a81b4)

Author SHA1 Message Date
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
jan iversen 9535dd87b0
Rename domain import in modbus (#33906) 2020-04-09 22:15:20 +02:00
jan iversen dd7fbef948
Fix modbus default delay (#33877)
* solve modbus issue #33872

CONF_DELAY was used in a serial connection, which is not
permitted.

Sometimes async_update is called after async_setup is completed,
but before event EVENT_HOMEASSISTANT_START is issued, leading to
a missing object.

* resolve review comment.

Do not wait for start event, but activate pymodbus directly in
async setup.

* review 2

Remark, this does not work, async_setup hangs.

clean start_modbus() from async calls, leaving only the pymodbus
setup.

* review 2a

Moved listen_once back to start_modbus, since it is sync.
2020-04-09 13:53:23 +02:00
jan iversen 2d1002d40d
Fix modbus transaction response (#33824)
Sometimes a modbus server do not respond to a transaction,
this is a contradiction to the modbus protocol specification,
but merely a matter of fact.

Use asynio.await_for() to provoke a timeout, and close the
transaction.
2020-04-08 13:04:47 -07: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
Franck Nijhof 39336d3ea3
Add prettier (in pre-commit and CI) (#33693)
* Add prettier (in pre-commit and CI)

* Make all file prettier

* Change order

* Add to Azure Pipelines

* Fix a YAML file prettier caught as invalid

* Remove flow mapping using curly braces from all YAML service files
2020-04-05 17:27:16 +02:00
springstan dde93304d3
Improve string formatting v2 (#33645)
* Improve string formatting v2

* Improve string formatting v3

* Address review comments
2020-04-04 23:09:34 +02:00
Paulus Schoutsen f1d3c0d19b
Remove unused manifest fields (#33595) 2020-04-03 12:58:19 -07:00
jan iversen ad8cf2d0d0
Remove Modbus legacy code (#33407)
* Modbus: remove legacy code

flexit and stiebel_el are updated to import modbus.const,
therefore legacy code can be removed.

* Flexit: update const reference from modbus

climate.py imports from modbus direct, this is legacy and will
result in errors.

update import to be modbus.const.

* Stiebel_el: update reference to modbus

__init.py references modbus directly, this is legacy and will
give errors.

Update import to be modbus.const.
2020-03-30 01:35:58 +02: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
springstan ba0aaeeddb
Use f-strings in integrations starting with "M" (#32271)
* Use f-strings in integrations starting with "M"

* Format mqtt light init with black

* Fix lint error

* Fix pylint error

* Restore constants

* Update homeassistant/components/mqtt/discovery.py

* Update homeassistant/components/mqtt/discovery.py

* Update homeassistant/components/mqtt/discovery.py

* Update homeassistant/components/mqtt/discovery.py

* Format with Black
2020-03-10 23:34:54 +01:00
Vladimír Záhradník 32cd58e03d
Modbus remove unnecessary get calls (#31966) 2020-02-18 19:41:12 -08:00