Implement config flow in the Broadlink integration#36914
Implement config flow in the Broadlink integration#36914MartinHjelmare merged 43 commits intohome-assistant:devfrom
Conversation
|
Hey there @Danielhiversen, mind taking a look at this pull request as its been labeled with a integration ( |
|
This PR is a great improvement. I had to work on many things which could not be done separately without causing pain to the users. So the PR ended up getting really big. But don't panic: many of these lines are just messages for the config flow 😄 I performed local tests and everything is working 🚀 @balloob @MartinHjelmare @Danielhiversen Do you have time to review? |
|
@felipediel Please, don't ping/mention for reviews to random people. That is not appreciated, instead have some patience while we working on the currently 400 open PRs in the organization. |
|
@frenck Thanks for the advice. I understand this and I am not pushing. Those guys are not random. I chose to torture them because they are familiar with this integration and I appreciate their reviews. If I were you, I wouldn't stare at this code for long. You can be the next 😄 @MartinHjelmare Thanks for helping me with this dinossaur. Tonight I will start working on the updates. |
|
@MartinHjelmare Do you think this is a good idea? |
|
I don't have the full context for how the availability works currently for broadlink. |
|
@Danielhiversen Could you help me to merge the latest updates in the library and release the new version? |
|
Okay, we're good to go. Sorry for these last commits, I had to fix some bugs and I did some changes that I consider really necessary to help the code grow clean. Soon we will be adding more samples to that device dictionary and we’ll be able to do mass testing. Wait for it. |
|
Yes. |
|
Please open a terminal on your computer, install the python-broadlink library ( import broadlink as blk
devs = blk.discover(timeout=5)
print([(d.host[0], hex(d.devtype)) for d in devs])
devs = blk.discover(discover_ip_address="192.168.0.17", timeout=5) # Your device IP address
print([(d.host[0], hex(d.devtype)) for d in devs])What is the output? |
|
Use your computer. I suggest you to create a venv. python3 -m venv venv
source venv/bin/activate
pip3 install broadlinkNow you can type |
|
Returns empty brackets "[]" |
|
Even if you try the second option? Are you using a VPN? |
|
[('192.168.1.48', '0x7540')] |
Oh gosh, are you sure? What is your device type? Please check if the entity_id is correct first. |
|
Actually it does not find it at all. The device is RM PRO. The script sees it anyway. device type '0x279d'. the config is under switch domain:
|
|
Should I manually add the existing device and re-learn all of my commands(IR/RF)? |
|
You don't need to relearn the commands. Did you add the device via config flow? Did you check the MAC address? |
|
After re-configure via Integrations, it is working. Sorry for bothering you. Do you know when the MP2 change will be released? in next patch or later? I am asking because it is connected to a lot of automations I have. :( |
|
I have no control over releases. I can help you to workaround:
ssh USERNAME@HOST
docker exec -it homeassistant /bin/bash
cd /usr/local/lib/python3.8/site-packages/broadlinkNow you are in the python-broadlink library folder. You can manually add your type to the file |
|
I am using HASSIO but not docker installation. |
|
Please open an issue if you suspect a bug. If you need help please use our help channels: Merged PRs should not be used for support or bug reports. Thanks! |

Breaking change
1. Devices are now configured via configuration flow
To set up a Broadlink device, click Configuration in the sidebar and click Integrations.
The devices will be imported from your configuration files to that page. If you see your device there, click Configure. If not, click the + icon in the lower right, click Broadlink, enter the host and follow the instructions to complete the setup.
The name you choose will serve as a template for the entities. You can change the entity name and id in the entity settings on the frontend. You may need to change some names or ids to make everything look the same as it was before this update.
2. Discontinue
broadlink.learnandbroadlink.sendservicesremote.learn_commandandremote.send_commandare now registered automatically. Now you can useremote.send_commandto send base64 codes.instead of
broadlink.learnuse
remote.learn_commandinstead of
broadlink.senduse
remote.send_commandkeep it clean
3. Discontinue all platforms, except switch
Entities are now registered automatically. The only exception is the switch platform, which continues to exist for RM switches. The config schema has changed. The host and type are no longer required and the name serves as a template for the entity id.
instead of:
use this:
The above example creates
switch.sony_tvandswitch.lg_tvto be controlled using the device with the MAC address 34:ea:34:b4:5d:2c. This device needs to be configured first via configuration flow.When you finish configuring the devices you can delete all your Broadlink configuration files except the RM switches. These switches are the only platform that still exists in yaml. They won't be imported. If you delete the file, they are gone.
The problem
Many users are having trouble configuring Broadlink devices. Broadlink recently launched an RM mini 3 - the infamous 0x5f36 - that is identifical to the others, but communicates differently, and the worse: it has a lock. I recently added support for these devices, but since we don't have device discovery, the user needs to specify the device type, so that the library can control it correctly. And if the device is locked, he needs to factory reset the device to unlock it.
But how can the user find out the device type? And how can he find out that the device is locked for authentication and needs a factory reset? The short answer is "read the docs", but the right answer is "he shouldn't have to do that".
We shouldn't be getting the device type from the user. The device knows its type and sends it in response when we say "hello". But we are skipping this step and going straight to authentication.
If we said hello, we could obtain valuable information in response, such as name, type, class, MAC address, model, manufacturer and lock. We are demanding a lot of these information from the user. He should not have to worry about these technical details.
Things could be simpler. We are breaking etiquette and making they pay for it. This PR comes to fix this.
Proposed change
This PR implements a config flow in the Broadlink integration.
In this flow, we say "hello" to the device and we create a config entry with the information we extract from the response.
The user no longer needs to provide the device type and MAC address.
The user no longer needs to set up platforms. We forward entry setup to related domains according to the device type.
The user gets notified when the device is locked, and a config flow is created to assist with unlocking.
Information such as name, model, manufacturer and firmware version are now available on the frontend.
Now the device is a singleton shared by the entities. This will improve communication as we will only have one connection per device.
Devices and entities are registered and associated. The entities are renamed when the device is renamed, updated when the device is updated, and removed when the device is removed. Everything happens in a coordinated and harmonious way.
Type of change
Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale: