Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadlink remote #26528

Merged
merged 11 commits into from Dec 2, 2019
Merged

Broadlink remote #26528

merged 11 commits into from Dec 2, 2019

Conversation

@felipediel
Copy link
Contributor

felipediel commented Sep 9, 2019

Description:

This PR introduces a new platform for controlling Broadlink remotes. I know, we already have the Broadlink switch platform that does pretty much the same. But I consider this an enhancement to the wonderful work started by mjg59 and Danielhiversen.

This integration introduces the following improvements:

  1. Instead of being treated as a switch, the Broadlink remote is now treated as a remote.

As a result, learning and command-sending services no longer need to be registered by the Broadlink component as they are already registered by the remote component.

  1. Command learning has become much easier.

The user no longer needs to learn one command at a time, check the persistent notification and then enter it manually into the configuration file as a switch. He can now use the following service:

- service: remote.learn_command
  data:
    entity_id: remote.bedroom
    device: television
    command:
      - turn on
      - turn off
      - channel up
      - channel down
      - volume up
      - volume down

This service allows the user to learn a sequence of commands very quickly. All the commands are stored in a JSON file and are easily retrieved by the command sending service. It also allows the user to capture toggle commands by using the 'alternative' flag:

- service: remote.learn_command
  data:
    entity_id: remote.bedroom
    device: television
    command: power
    alternative: True

When calling the command learning service with this flag, two codes will be captured for the same command, and will be sent alternatively each time the command is called.

  1. Command sending has become much powerful.

Now the user can send several commands sequentially, and can repeat the sequence as many times as desired. Suppose the user wants to turn on the air conditioner and then turn off the annoying display light with a single service call. He can do something like this:

- service: remote.send_command
  data:
    entity_id: remote.bedroom
    device: air conditioner
    command:
      - turn on
      - turn off display

Now suppose the user wants to increase the volume of the television by 20. He can do something like this:

- service: remote.send_command
  data:
    entity_id: remote.bedroom
    device: television
    command: volume up
    num_repeats: 20

I use this powerful tool combined with a data template to voice control the volume of my TV. I can say things like "Alexa, set TV volume to 50". If you want to know how I do it, just ask me and I send you the config.

So that's it, I hope you enjoy this integration and make good use of it. And if there is anything I can do to make this code better before it is merged please let me know and I will do it.

Related issue (if applicable): #23888

Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#10329

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly. Update and include derived files by running python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.
felipediel added 4 commits Jun 15, 2019
Sync the fork to the original repository
Sync the fork to the original repository
@frenck

This comment has been minimized.

Copy link
Member

frenck commented Sep 9, 2019

⚠️ I was unable to find a documentation PR (matching this code change) in our documentation repository.

Please, update the documentation and open a PR for it (be sure to create a documentation PR against the next branch) and link 🔗 this PR and the new documentation PR by mentioning the link to the PR's in both openings posts/descriptions.

🏷 I am adding the docs-missing label until this has been resolved.

@frenck frenck added the docs-missing label Sep 9, 2019
@felipediel felipediel mentioned this pull request Sep 9, 2019
2 of 2 tasks complete
@felipediel

This comment has been minimized.

Copy link
Contributor Author

felipediel commented Sep 9, 2019

warning I was unable to find a documentation PR (matching this code change) in our documentation repository.

Please, update the documentation and open a PR for it (be sure to create a documentation PR against the next branch) and link link this PR and the new documentation PR by mentioning the link to the PR's in both openings posts/descriptions.

label I am adding the docs-missing label until this has been resolved.

Done.

@frenck frenck removed the docs-missing label Sep 10, 2019
@a005

This comment has been minimized.

Copy link
Contributor

a005 commented Nov 15, 2019

Now the user can send several commands sequentially, and can repeat the sequence as many times as desired. Suppose the user wants to turn on the air conditioner and then turn off the annoying display light with a single service call. He can do something like this:

- service: remote.send_command
  data:
    entity_id: remote.bedroom
    device: air conditioner
    command:
      - turn on
      - turn off display

Now suppose the user wants to increase the volume of the television by 20. He can do something like this:

- service: remote.send_command
  data:
    entity_id: remote.bedroom
    device: television
    command: volume up
    num_repeats: 20

It is not clear to me how to combine sending several commands and repeating some commands at the same time.


async def async_turn_on(self, **kwargs):
"""Turn the remote on."""
self._state = True

This comment has been minimized.

Copy link
@balloob

balloob Nov 26, 2019

Member

What's this. I guess this remote has no state ? In that case let's not fake it but instead just return None from the state property.

This comment has been minimized.

Copy link
@felipediel

felipediel Nov 26, 2019

Author Contributor

I find the state a useful way to disable the remote when needed. Sometimes I need to adjust the controls on the frontend without sending codes (to sync something like a device state or volume level) and having a disable button makes it a lot easier. It's a matter of usability, which can be redesigned if you wish.

Copy link
Member

balloob left a comment

This looks great. Some updates needed but off to a good start. This will be a great improvement!

Since this is a significant change for the broadlink integration, please add yourself to the manifest as a code owner 👍

Dev automation moved this from Needs review to Review in progress Nov 26, 2019
homeassistant/components/broadlink/remote.py Outdated Show resolved Hide resolved
homeassistant/components/broadlink/remote.py Outdated Show resolved Hide resolved
homeassistant/components/broadlink/remote.py Outdated Show resolved Hide resolved
homeassistant/components/broadlink/remote.py Outdated Show resolved Hide resolved
homeassistant/components/broadlink/remote.py Outdated Show resolved Hide resolved
@felipediel

This comment has been minimized.

Copy link
Contributor Author

felipediel commented Nov 26, 2019

It is not clear to me how to combine sending several commands and repeating some commands at the same time.

You could definetely do both.

  - service: remote.send_command
    data:
      entity_id: remote.bedroom
      device: some_device
      command:
        - 1
        - 2
        - 3
      num_repeats: 2

The num_repeats is the outer loop, so this script it will send 1 2 3 1 2 3.

@felipediel

This comment has been minimized.

Copy link
Contributor Author

felipediel commented Nov 26, 2019

I will start working on the improvements now and respond to other comments as their requirements are completed.

@a005

This comment has been minimized.

Copy link
Contributor

a005 commented Nov 26, 2019

The num_repeats is the outer loop, so this script it will send 1 2 3 1 2 3.

How to send 1 2 2 2 ?

@balloob

This comment has been minimized.

Copy link
Member

balloob commented Nov 26, 2019

@a005 that is an issue for the remote integration, not for the broadlink implementation.

@balloob
balloob approved these changes Dec 2, 2019
@balloob balloob merged commit 5a24dbf into home-assistant:dev Dec 2, 2019
11 checks passed
11 checks passed
CI #20191202.38 succeeded
Details
CI (FullCheck Mypy) FullCheck Mypy succeeded
Details
CI (FullCheck Pylint) FullCheck Pylint succeeded
Details
CI (Overview CheckFormat) Overview CheckFormat succeeded
Details
CI (Overview Lint) Overview Lint succeeded
Details
CI (Overview Validate) Overview Validate succeeded
Details
CI (Tests PyTest Python36) Tests PyTest Python36 succeeded
Details
CI (Tests PyTest Python37) Tests PyTest Python37 succeeded
Details
cla-bot Everyone involved has signed the CLA
codecov/patch Coverage not affected when comparing 28beeba...a105b38
Details
codecov/project 94.44% (target 90%)
Details
Dev automation moved this from Review in progress to Done Dec 2, 2019
@balloob

This comment has been minimized.

Copy link
Member

balloob commented Dec 2, 2019

Very nice! 🎉

@lock lock bot locked and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Done
6 participants
You can’t perform that action at this time.