-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Ensure backwards compatibility #187
base: main
Are you sure you want to change the base?
Conversation
- Mark the name field as private - Add a name property to get the first (most common) name - Add a function to get all supported names
Coverage Report
|
0c729d5
to
3c28cd9
Compare
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.
LGTM
I'll wait for @gerw s review on this before merging it |
Due to a bug in v0.3.14 / visibilities.py / line 380 all visibilites above 354 are labeled "Unknown_Parameter_xxx" instead of "Unknown_Visibility_xxx"
I am a little bit biased, because I wrote the previous PR #171. I have had a careful look at both PRs and I must admit that I like my PR more. In my opinion,
|
Everyone has their own coding style :) In my opinion, an additional file is more difficult to maintain. Especially since sometimes 3 names are used (see
To get around this, we could add the following:
Then at least
I think we could also use the test code for this. BTW, your test doesn't reveal the bug in Visibilities with the index > 354. there is simply no such thing as 100% test coverage :) |
Now `_names` within `Base` is always a list.
21b3aca
to
2417b3e
Compare
2417b3e
to
b5cd90b
Compare
Updated source code to:
|
I still think it is more in the style of this library, if the
compatibilities reside in their own file. Note that the constants have
been moved to a separate file some time ago. In the same spirit, the
compatibilities should be in a separate file and should not "pollute"
other files.
I do not see the benefit of this new PR over #171
What do the others say in this regard? @Bouni @kbabioch
|
Please note that the current implementation in #171 cannot handle further name changes. As an example, if you change a name from
In addition, you may run into problems if entries from two different data vectors have the same name. Of course it makes sense to put the constants in an extra file. However, the goal of that is to remove or reduce dependencies between the files. I see the advantage of my implementation as:
The concrete implementation of the data vectors is now nothing more than the assignment of names to the indices. I see no reason that outdated names need to be outsourced. |
I just looked at both, this PR and #171 I like the idea of @Guzz-T to have names as a list and have the first element to be the prefered one and all after that the obsolete names. On the other hand, I agree with @gerw that we should have these in a seperate constants file. How about we merge both approaches? We have a constants file like this (with a tubple of tuples for each, parameters, calculations and visibilities): LUXTRONIK_PARAMETER_COMPATIBILITIES = (
("New_fancy_name", "ID_Einst_SuSilence", "Unknown_Parameter_1092"),
("ID_Einst_SilenceTimer_0", "Unknown_Parameter_1093"),
("ID_Einst_SilenceTimer_1", "Unknown_Parameter_1094"),
("ID_Einst_SilenceTimer_2", "Unknown_Parameter_1095"),
...
) Then we change the 3 categories (parameters for example) like so: ...
self._data = {
0: Unknown(),
1: Celsius(True),
2: Celsius(True),
3: HeatingMode(True),
4: HotWaterMode(True),
... We then lookup the possible names by the number of the parameter, calculation or visibility. If the lookup is done via name, we have to iterate over the const until we find the right entry, but that has to be done in either of your approaches anyway if I'm right. What do you think? |
With this proposal, it is even more difficult for the user to look up the assignment of the names to the data types. Should the user work with the constants at all? If not, then I would not implement constants. |
I would also prefer if LUXTRONIK_COMPATIBILITIES = {
"ID_Einst_SuSilence" : ["Unknown_Parameter_1092", "bar", "foo"],
....
} where |
For the same reason I would also include the “alternative” names in parameter.py. only if you insist on outsourcing the “alternative” names. In this case I would like your current suggestion better. If so, how should we deal with the following:
|
But the user does not have to look up the old names?
Is this really an issue? Is there some example where we have a name clash? (I know that 0.3.14 uses
I am not sure. In my opinion, it would be enough to access the current name of a property, but this should be possible by parameters.get("outdated_name").name |
I mean, anyone who has worked with this repository is used to looking in the
That's exactly what I thought of first. See BenPru's usage of |
[Update]: [Original]: op_mode = lux.calculations.get("Unknown_Calculation_80") # outdated name for "ID_WEB_WP_BZ_akt"
op_mode.raw = 1 # op_mode.value returns "1"
if op_mode.value == 1: # evaluates to "true"
... In this example, an object of type op_mode = lux.calculations.get("Unknown_Calculation_80")
op_mode.raw = 1 # op_mode.value returns "hot water"
if op_mode.value == 1: # evaluates to "false"
... This construct would be a possible solution: self._data = {
...
80: [OperationMode("ID_WEB_WP_BZ_akt"),
Unknown("Unknown_Calculation_80")],
... or self._data = (
...
([38], OperationMode("ID_WEB_WP_BZ_akt")),
([38], Unknown("Unknown_Calculation_80")),
([81..90], IPv4Address("ID_WEB_SoftStand")),
... To be able to handle type changes without name changes, we could implement a factory pattern (something like this): class CalculationsFactory:
@classmethod
def get_calculations_data(cls, interface_version):
if interface_version == "v1":
return {
38: Unknown("ID_WEB_BZ_akt"),
...
}
if interface_version == "v2":
return {
38: OperationMode("ID_WEB_BZ_akt"),
...
}
class Calculations(DataVector):
def __init__(self, interface_version = "v2"):
super().__init__()
self._data = CalculationsFactory.get_calculations_data(interface_version) |
…d (BenPru's HA-Integration)
Some of the changes in this pull request go beyond just informing the user about the new names. My focus here was on the direct interchangeability of the versions. However, this is not strictly necessary. Do you see it differently? As a result, I created pull request #191. |
Hi everyone, sorry for the long silence. Free time is a rarity in the last months .... Regarding name overlapsas mentioned by @Guzz-T s question in #187 (comment)
I did a quick check and searched all names in all 3 groups for overlaps. There are None so we can rule that out. Regarding the lookup issue for the userAs I proposed in #189 I did a first draft in #192 which autogenerates docs for the user to lookup the desired names / ids in a GH pages page: https://bouni.github.io/python-luxtronik/ This gives the user the ability to search through the 3 groups to find the wanted entry. I could imagine to add a In my opinion its a bad idea to let the user search through the code for the desired name / id. Concider this a draft with much room for improvement. Regarding outdated namesWe should print a warning that an outdated name is used and directly show the new name in that message. I'm also not sure if we should keep that burden of keeping old names at all. Maybe we shoud just raise an Exception if the name is not found. For me the next release should also bump to the next minor version (0.4.0 I guess) to indicate that this might contain breaking changes. On the other hand I like the idea of non breaking stuff, but it makes it harder to keep the library slim and easy to understand. Isn't it enough to have a good changelog which indicates breaking changes!? |
But if we drop the old names, how could the user be informed of the new name? |
Raise an exception maybe!? |
The more I think about it, maybe we should disencourage or drop the use of the name all together an only allow the ID 🤔 Combined with the auto generated docs its easy for a user to look up the desired ID. |
With the changes from these pull requests, the corresponding entries can be found under the old names again. This is possible because you can now assign more than one name to the entries.
The names are passed directly to the constructor. No additional files / additional constants are required. It is therefore immediately clear which names can be used to find the entry.
The current version can now be exchanged with version 0.3.14. Tested with BenPru/luxtronik/2024.10.5-beta on HA 2024.10.4 (with own bugfix for BenPru/luxtronik#283). A new release could then be created (0.4.0?)
Fixes #168.
Replaces #171.