-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
[Pilight switch] Allow arbitrary command scheme #5223
Conversation
@@ -11,8 +11,7 @@ | |||
import homeassistant.helpers.config_validation as cv | |||
import homeassistant.components.pilight as pilight | |||
from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA) | |||
from homeassistant.const import (CONF_NAME, CONF_ID, CONF_SWITCHES, CONF_STATE, | |||
CONF_PROTOCOL) | |||
from homeassistant.const import (CONF_NAME, CONF_SWITCHES, CONF_PROTOCOL) |
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.
'CONF_PROTOCOL' imported but unused
This fix seems to work and seems not to break pilight switch configs. @janLo Maybe you have time to check with your more fancy config, since you use templates etc.? |
vol.Optional(CONF_ID): cv.positive_int, | ||
vol.Optional(CONF_STATE): cv.string, | ||
vol.Optional(CONF_SYSTEMCODE): cv.positive_int, | ||
vol.Required(vol.Any(str)): vol.Any(str, int, float) |
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.
Probably want to use vol.Coerce(str)
for key, that way you convert it to a string if it is not.
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.
That should be fine, because numbers as a protocol key do not exist. Think of it as a python dictionary with string keys and string/int/float values.
I'm not convinced to that. Instead of providing a proper implementation to the API we decide to revert it and give the responsibility to implementing the pilight API correctly to the user I their configurations. And all because we fear, that pilight might change its API somehow in the future. That's if we gust let the user put its own HTTP requests into the configuration for weather components because we fear that the service might change its API in the future. Of course, it's more flexible but the we should not call it an API implementation. |
A proper implementation to the API is impossible without reimplementing it (the protocol info is not available by the c-library of pilight). And that would be not proper in my terms.
It is only about Is the value a string or number? Yes the user has to chose the correct type.
That is only one point I mentioned. Additionally it is error prone and self defined protocols do not work. And it requires maintenance neither me nor you are able to provide. Is it clear to you e.g. that to fix #5119 with your proposed feature Protocol validation at startup you have to make a voloptuous rule with ALL pilight protocolls? Why don't you get that this is insane to do?
You gave it this name. For me it just a generic way to use all pilight supported 433 MHz devices. |
@DavidLP although pilight supports arbitrary protocols, if we know that a unit, unit code or id are always positive ints, a schema could proof useful. The schema is defined with |
We started adding voluptuous schemas all over Home Assistant to help guide our user. Either by coercing their passed in data into the correct values or being able to give them sensible feedback. This has helped the user experience tremendously. |
We do not really know that. For example this was wrongly assumed for
I agree. But this is only possible for backends that either expose their API (pilight does not yet) or that are so simple that you can define the type for all possible keys (more than 100 keys in more than 60 different combinations for pilight). What I feared (and happened) is that we assume to know something about a key, are proven wrong at some time, and have to do bug fix after bug fix. I cannot provide this and if I weigh less feedback against possible bugs I go for the first in terms of user experience. Also keep in mind that pilight users might implement their own protocol and that this might be rejected by home assistant. Since you are the maintainer I leave you two choises :-D:
|
In the case of |
Good idea, but unfortunately it does not work. I checked. |
The only solution right now for protocol validation at hass start-up is to reverse engineer all protocols c-code and create voloptuous schemes from this. I wrote a protocol parser that is capable of doing this and it seems to work fine. But implementation into hass will take me some time and needs proper testing, and options to deactivate protocol validation and to set the protocol level (debug, release x). |
I do not recommend parsing the c code. This is where you really go to a maintainance hell. Have you had a look at this approach: DavidLP/pilight#3 ? |
I just saw. Yes let's do it this way. I will review you PR. |
Description:
There was an attempt to do command scheme validation with voloptuous. But since the command
scheme is arbitrary and pilight does not provide an interface (yet) to get allowed commands anything should be allowed.
Related issue (if applicable): fixes #5119
Example entry for
configuration.yaml
(if applicable):Checklist:
If the code does not interact with devices:
tox
run successfully. Your PR cannot be merged unless tests passTests have been added to verify that the new code worksMore like: test have been done with 3 different installations + hardware to be able to claim that this code works better.Remark:
Since this could break something I am not aware of (for me it works) I would delay this merge until I get feedback in the forum.