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
Add samsungtv.turn_off
trigger
#91903
Conversation
Hey there @chemelli74, @epenet, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
This is fully working on my local, testing against my Samsung TV device. I will wait until I receive a positive feedback before start working on the documentation PR. |
samsungtv.turn_off
trigger
@@ -0,0 +1,108 @@ | |||
"""Samsung TV device turn off trigger.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is 99.7% similar to turn_on.py
. You should reuse the code not duplicate it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm too dumb to do this. I got little to no Python experience. I really tried though. Would you mind doing it yourself? I can give you the needed permissions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding a new module turn_off.py
do something like this:
- rename
turn_on.py
toturn_on_off.py
- rename
async_get_turn_on_trigger
toasync_get_turn_on_off_trigger
and make it return a list with both the triggers - update
async_attach_trigger
to checkconfig[CONF_TYPE]
and set the description accordingly
triggers = [ | ||
async_get_turn_on_trigger(device_id), | ||
async_get_turn_off_trigger(device_id), | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
triggers = [ | |
async_get_turn_on_trigger(device_id), | |
async_get_turn_off_trigger(device_id), | |
] | |
triggers = async_get_turn_on_off_triggers(device_id), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion but it's a lot more complicated than that. For example, I have to refactor attach_trigger, media_player.py and triggers.py. I just spent 2 hours trying to do it, and it ended up not working.
I'm pushing my draft changes if you want to review them.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return await platform.async_attach_trigger(hass, config, action, trigger_info) |
platform_type does not have default value now so you have to define it:
+ return await platform.async_attach_trigger(hass, config, action, trigger_info, platform_type=config[CONF_PLATFORM])
This fixes all but 3 errors in turn_off tests. I don't know fix these.
@MichaelMraka thanks for the hint. The fix ended up being a little different though, but around the same place. I'll investigate the rest of the issues but I believe it may have something to do with this: |
I'd start by investigating more about the issue first before going ahead with this PR. Why doesn't turn off work for the device? |
Me too. And I did that: But there is no solution. And considering that https://github.com/Ape/samsungctl is unmaintained since 2019, I believe there is virtually no chance of having a fix for it in the library. |
We don't know what's wrong yet so we don't know where to fix it. I suggest continuing troubleshooting until there's some lead on what's the problem. Codeowners may have suggestions for troubleshooting steps. |
Ok. My understanding was that my device is simply unable to receive such command and thus this PR would make sense. But it's true that's my understanding only, which may be wrong. Any help is appreciated. |
It may be that in the end we will conclude that the device doesn't support turn off but I don't think that's confirmed yet. |
@chemelli74 @epenet maybe you can recommend any troubleshooting step, or advise if you believe this PR is the best we can do about it. I don't think anyone else will be able to help us otherwise. |
I was able to work around this issue by building an automation which achieves the same result: alias: Turn off action for home theater
description: ""
trigger:
- platform: state
entity_id:
- media_player.home_theater_do_escritorio
from: "on"
to: "off"
condition:
- condition: template
value_template: >-
{{ trigger.to_state.context.user_id is not none or
trigger.to_state.context.parent_id is not none }}
alias: Confirm is triggered by turn_off service
action:
- service: remote.send_command
data:
device: home_theater_do_escritorio
command: power
target:
entity_id: remote.rm4_pro_remote
mode: single Thus I'm closing this PR. |
Breaking change
Not a breaking change.
Proposed change
This adds the
samsungtv.turn_off
trigger, so that users can specify their own automations to turn off the Samsung TV, which is useful when the default does not work.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
.To help with the load of incoming pull requests: