-
Notifications
You must be signed in to change notification settings - Fork 91
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
KNX Plugin improvement for DPT 2 (num instead of list) #291
Comments
If we want to change this, we should also change this for DPT 3
(from https://www.smarthomeng.de/user/plugins/knx/README.html) Should be simple to implement: I would just check the given value's type and in case it's not a list try to convert it to an |
Problem might occur when receiving the value from the knx device. Maybe there is a scenario where someone wants to have the response as a list? So I guess there needs be an option in the config? |
I had a closer look at the dpt handling.
Although the decoding is contra-productive as it converts an int to a list again on receiving a value:
So I guess the better solution might be to check the type of the item in the parse_item function and maybe internally change the dpt to a "subtype" like 2001 with the corresponding functions in dpts.py |
There are defined subtypes for dpt 2 in the KNX specification (2.001 - 2.012), so we should take care not to create conflicts. I am going to look deeper into the KNX specification. Same goes for dpt3. Defined subtypes are 3.007 and 3.008 |
dpt 2.003 to 2.012 are only for KNX internal use (function blocks) only dpt 2.001 and 2.002 are for general use. We could do something like this:
Another approach could be to use the casting functionality of items:
item1 would receive a list and item2 would receive a number. This casting functionality is already used in the mqtt plugin. Since the MQTT payload is an array of byte, the content gets interpreted using the type-defiinition of the item. |
I would totally vote for the second approach. |
I would prefer the first approach. As long as the knx dpt are just a single int or so it's not a problem but what is with composed datatypes like 6.5.1 DPT_DALI_Control_Gear_Diagnostics? None of above conversion method seems appropriate. One might take a dict here to store the components but then it's not a real item any more. Any ideas for those cases? |
I think the first approach is simpler to manage and thus less fault-prone. DPT 3.007 and 3.008 could be represented as negative and positive integers if item is of type num. @bmxp I don't share your point for two reasons:
BTW: Why is an item of type dict not a real item? The mention of a dict leads to another option: |
That assumtion is wrong. In variant 1 you have to change the knx_dpt (from 2 to 2.001). In the second variant you have to change the type (form list to num).
Why do you think so? It is! |
I don't understand what you mean.
Why? If you define the Item to be of type dict it is still a real item. |
I was wrong above. For the first approach you have to change type and knx_dpt! Another problem with the first approach is, that when using e.g. 2.001 to convert to a num value, you use one definition of "two bits" to convert to a list of bits and another definition which from the knx perspective is "two bits" too, and convert it to a num. For second approach it could be said like "I know that it is a "two bit" value, but I want to interpret it as number (or to interpret it as list). We could even think about a third conversion (to a dict) like this:
|
I'm not sure if I misunderstand something, but in variant 1 you have to change the knx_dpt and the item type, don't you?
@bmxp wrote this 😄 EDIT: You were faster than me 😃 |
Yes, but you wrote that for the second variant you would have to change both. |
Sorry, that was a misunderstanding because of the ambiguity of the word "otherwise". |
The point with item type dict is that changes within the dict won't be detected as such.
currently this will not be detected by SHNG, thus the new value won't trigger anything, not cached or written somewhere. I think this might be a problem. Otherwise I am fine with dict and would favour that. You can use
|
But that's a problem which has to be solved anyhow as the type dict is already implemented and documented. BTW: Is the triggering working for lists? |
This is true in Python for all complex datatypes. And for shNG it is not true any more. A couple of weeks ago this changed. Since beginning of September complex datatypes are handles via deepcopy see #274.
Because of that, I think approach 2 is easier to understand. |
Since beginning of September (lists are complex datatypes too) |
IMHO we should have lists for complex datatypes. If we needed dicts, we always need to have a key as well. |
This issue has been moved to the plugin repo: smarthomeNG/plugins#565 |
To easily change DPT 2 knx entries via VISU it would be more comfortable to set priorities not only as lists but also as a number. The ETS converts simple numbers to lists as follows:
0 = [0,0]
1 = [0,1]
2 = [1,0]
3 = [1,1]
Such an internal conversion for DPT2 items would be very nice or are there any reasons this is a bad idea?
The text was updated successfully, but these errors were encountered: