Wake on LAN for UI-configured Samsung TVs#33621
Conversation
|
@escoand this PR is just a placeholder and has no real functionality yet. If you think this is the right approach, I'll go ahead and complete it. |
|
@escoand let me know what you think. I'll happily complete this if you think this direction makes sense. |
|
@OnFreund Can you put the PR into "Draft" in the mean time? There is a "Convert to draft" in the reviewers section in the sidebar of this PR. |
|
@OnFreund Interesting, never used such a options flow. How to use/test this? |
|
Once I implement this, it will be available as a gear button on the integration page. The demo integration has a functioning example that doesn't require special hardware. |
|
Nice, would love to see this. Best would be something like the automation editor UI (my TV is not able to wake-on-lan), but let's start with the MAC. |
|
The UI in options flow is very limited (same as config flow). We could potentially have a field for service name, and a field for json arguments, but there will be no autocompletion, and high possibility of misconfiguration. |
|
@escoand this is the implementation I had in mind. There's one weird test failure that I can't understand, and a small section I'm not sure how to test. |
| except socket.gaierror: | ||
| current_mac = None | ||
|
|
||
| schema = {vol.Optional(CONF_MAC, default=current_mac): str} |
There was a problem hiding this comment.
Is there a cv type for mac address validation? Your current implementation accepts everything if I'm right.
There was a problem hiding this comment.
Unfortunately there isn't. According to home-assistant/architecture#222 there also might never be.
|
|
||
| async def async_step_init(self, user_input=None): | ||
| """Manage the options.""" | ||
| if user_input is not None: |
There was a problem hiding this comment.
The only risk here is a malformed MAC address, which is no different than a wrong MAC address. This is an advanced feature, and the input will most likely be pasted (unless obtained automatically). The wrong/malformed address will fail quickly and be easy to fix. Given all of the above, I don't think the validation overhead is worth it.
I've also quickly searched through the code base and couldn't find an integration that validates mac addresses.
|
@escoand I think the request review button isn't working for this PR. |
escoand
left a comment
There was a problem hiding this comment.
Have not tested it, but it looks good in theory.
|
Thanks. I tested it locally and it's working well. I still don't understand that test failure, though. @MartinHjelmare any chance you can help with that? |
|
thanks @MartinHjelmare your suggestion fixed it. @escoand in order to simulate this and test this case locally, I added a config entry with an invalid hostname. The logs are now full of: Might be worth seeing if this could be more gracefully handled. |
7f046c0 to
c2695fa
Compare
|
@OnFreund how did you add an invalid hostname? The config flow in the UI should fail. Have you edited the config entry? |
|
Yes, I edited the config entry. It's an edge case, but it could happen, if for example, the IP changed. |
c2695fa to
52c46df
Compare
|
I don't have statistics over wol-able TVs but from the issues I had seen there are quite much which aren't. And from my point of view I don't like the idea of automatically created automations. Let's discover the mac address and push it along. But AFAIK this is impossible in some situations (e.g. VLAN), so we will end up with an unreliable solution. |
|
I think it would be better with a WOL switch entity, that will discover the Mac of a device on setup (config flow). That way the automation just need to trigger the switch. |
|
@elupus And whats the difference between the switch and the de-facto switch when adding the trigger? I would say the second is even better because you don't have an additional switch entity which is actually NOT a switch but just a trigger. |
|
Just the MAC address lookup. By a standard config entry, the MAC address can be deduced during config and stored. If unable to ARP find it, you can manually enter it. WOL can work between VLAN if the broadcast domain of the subnet the other device is on is known. However, if the MAC address is known by this integration by some other mean rather than ARP (sometimes exposed in metadata and/or SSDP discovery). Exposing hostname/ip as well as MAC in the event would allow hookup to a standard WOL service without a separate switch. My point is really, i don't think this integration should try to deduce MAC, if the only reason is WOL. Separation of concerns. |
|
I think that users expect the ability to turn the device on to be supported without too much configuration. WOL is a common way to achieve that (probably the common way, by far, and also the one that's currently detailed in the docs), so I would think we should lower the barrier to using it, which means automatically obtaining the mac address. |
|
I was wondering how we could avoid all the "power button is not working" issues. What do you think of creating a default-deactivated automation and give a hint in the config flow that's maybe possible and the user has to try and activate/drop it? The solution with the extra switch entity is the least preferred one. |
|
I like this (are there precedents of config flows creating automations?) as it reduces the friction to creating a functioning turn-on implementation in the common case. However, If I understand correctly, you would still have a "power button is not working" situation, it would just be a bit more explicit. I'm not sure we can have the cake and eat it too - the event based solution has a lot of pros, but has a clear unmitigated con in the form of the power button not working unless setup. If we go with it, we need to live with the consequences. |
|
Yes, we could still have this issues, but when removing yaml some day, every user has the change to read this hint. One other thing which comes to my mind: we have to setup wakeonlan as well. |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
Seems like we have one solution that is generic and configurable (device trigger), and one that has a better user experience (
This approach is fully generic and configurable, while also implementing |
|
Sorry for the delay, forgot to answer. Your proposal is probably working, but as you already mentioned it's a bit a hacky for the user. Your only problem with the device trigger is the missing support flag, right? The UI is already able to list every use of an entity. Couldn't we use this discovery to add |
|
Could we additionally init a new automation edit screen as done from the device page and add a wake-on-lan call? |
I wouldn't call it "hacky". Yes, the initial setup is a bit more complicated, but ongoing functionality is better, I believe, for two reasons:
|
|
Anyway, I'm more than happy to tackle the "mac address as attribute" part. I'll defer to you on how to actually handle the turning on part. |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
@escoand let me know if you'd like me to tackle the "mac address as attribute" part |
|
Yeah, do like you want. I haven't more or less to decide than any other. I've just added myself as codeowner to be informed not because I think the code is my own... |
|
Yes, but eventually you'll be tagged for a review, so I want to make sure you're not categorically against it before I invest time :) |
|
I suggest making an issue in our architecture repo first. |
|
Fair enough. I also have an idea how to make it more generic. |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
The idea I had in mind is actually very similar to the new automation variables in 0.115. |
Proposed change
When configuring a Samsung TV through YAML, you can define an action to turn it on. This configuration is not available through the UI (for either manually initiated or through discovery).
Since I assume that in most cases the turn-on action would be wake on lan (and for more advanced cases one can use a universal media player), this PR adds the ability to set a MAC address through an options flow, which will be used to turn the TV on through wake on lan.
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: