Implement config flow in the Broadlink integration (#36914)

* Implement config flow in the Broadlink integration

* General improvements to the Broadlink config flow

* Remove unnecessary else after return

* Fix translations

* Rename device to device_entry

* Add tests for the config flow

* Improve docstrings

* Test we do not accept more than one config entry per device

* Improve helpers

* Allow empty packets

* Allow multiple config files for switches related to the same device

* Rename mock_device to mock_api

* General improvements

* Make new attempts before marking the device as unavailable

* Let the name be the template for the entity_id

* Handle OSError

* Test network unavailable in the configuration flow

* Rename lock attribute

* Update manifest.json

* Import devices from platforms

* Test import flow

* Add deprecation warnings

* General improvements

* Rename deprecate to discontinue

* Test device setup

* Add type attribute to mock api

* Test we handle an update failure at startup

* Remove BroadlinkDevice from tests

* Remove device.py from .coveragerc

* Add tests for the config flow

* Add tests for the device

* Test device registry and update listener

* Test MAC address validation

* Add tests for the device

* Extract domains and types to a helper function

* Do not patch integration details

* Add tests for the device

* Set device classes where appropriate

* Set an appropriate connection class

* Do not set device class for custom switches

* Fix tests and improve code readability

* Use RM4 to test authentication errors

* Handle BroadlinkException in the authentication
This commit is contained in:
Felipe Martins Diel 2020-08-20 12:30:41 -03:00 committed by GitHub
parent eb4f667a1a
commit a2c1f08c8c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 2497 additions and 795 deletions

View file

@ -1,41 +1,15 @@
"""Constants for broadlink platform."""
from datetime import timedelta
CONF_PACKET = "packet"
DEFAULT_NAME = "Broadlink"
DEFAULT_PORT = 80
DEFAULT_RETRY = 3
DEFAULT_TIMEOUT = 5
"""Constants for the Broadlink integration."""
from homeassistant.components.remote import DOMAIN as REMOTE_DOMAIN
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
DOMAIN = "broadlink"
LEARNING_TIMEOUT = timedelta(seconds=30)
DOMAINS_AND_TYPES = (
(REMOTE_DOMAIN, ("RM2", "RM4")),
(SENSOR_DOMAIN, ("A1", "RM2", "RM4")),
(SWITCH_DOMAIN, ("MP1", "RM2", "RM4", "SP1", "SP2")),
)
SERVICE_LEARN = "learn"
SERVICE_SEND = "send"
A1_TYPES = ["a1"]
MP1_TYPES = ["mp1"]
RM_TYPES = [
"rm",
"rm2",
"rm_mini",
"rm_mini_shate",
"rm_pro_phicomm",
"rm2_home_plus",
"rm2_home_plus_gdt",
"rm2_pro_plus",
"rm2_pro_plus2",
"rm2_pro_plus_bl",
]
RM4_TYPES = [
"rm_mini3_newblackbean",
"rm_mini3_redbean",
"rm4_mini",
"rm4_pro",
"rm4c_mini",
"rm4c_pro",
]
SP1_TYPES = ["sp1"]
SP2_TYPES = ["sp2", "honeywell_sp2", "sp3", "spmini2", "spminiplus"]
DEFAULT_PORT = 80
DEFAULT_TIMEOUT = 5