-
-
Notifications
You must be signed in to change notification settings - Fork 31.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
Reintroduce unique_id for Netatmo sensor #18774
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For the interpretation of voltage values the different types of netatmo modules need to be distinguished. This is currently done by selecting the second character of the modules '_id'. The _id-field actually contains a mac address. This is an undocumented way of identifying the module_type. The netatmo API also delivers a field called 'type' which provides a more consistent way to differentiate the fields. This commit introduces a differentiation which uses this provided type. This should improve readability. Also the field module_id is renamed to module_type which should better resemble what it actually represents.
Each netatmo module features a unique MAC-Address. The base station uses an actual assigned MAC Address it also uses on the Wifi it connects to. All other modules have unique MAC Addresses which are only assigned and used by Netatmo on the internal Wireless-Network. All theses Addresses are exposed via the API. So we could use the combination MAC-Address-Sensor_type as unique_id. In a previous commit this had already been tried but there was a misunderstanding in what the 'module_id' represented. It was actually only a module_type representation so it clashed when two modules of the same type where used.
homeassistant
added
platform: sensor.netatmo
small-pr
PRs with less than 30 lines.
cla-signed
labels
Nov 29, 2018
ghost
added
the
in progress
label
Nov 29, 2018
houndci-bot
reviewed
Nov 29, 2018
fabaff
changed the title
Sensor/Netatmo: reintroduce unique_id
Reintroduce unique_id for Netatmo sensor
Nov 29, 2018
pvizeli
reviewed
Nov 30, 2018
@@ -112,9 +117,11 @@ def __init__(self, netatmo_data, module_name, sensor_type): | |||
self._device_class = SENSOR_TYPES[self.type][3] | |||
self._icon = SENSOR_TYPES[self.type][2] | |||
self._unit_of_measurement = SENSOR_TYPES[self.type][1] | |||
module_id = self.netatmo_data.\ | |||
self._module_type = self.netatmo_data. \ | |||
station_data.moduleByName(module=module_name)['type'] |
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.
Why you use this variable?
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.
It is needed in the update function to distinguish the module type to calculate the correct battery level.
pvizeli
approved these changes
Dec 1, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
Short:
This commit adds back the unique_id property for Netatmo sensors with a really unique value. Additionally it makes the differentiation of Module Types more intuitive.
Long:
In commit e51427b there was already an attempt to add a
unique_id
in the new Entity Registry style to the Netatmo sensor. This assumed, that the value ofself.module_id
was a value unique for each Netatmo Module. (actually it changed from usingmodule_id
which was unique toself.module_id
which was not unique for theunique_id
)This assumption was wrong as PR #4724 introduced a
self.module_id
which differed frommodule_id
as it was defined like this:
So
self.module_id
was actually only the second char of themodule_id
(which is a MAC Address). This was used in the Battery Code to destinguish between the different types of modules. So it was actually more representing amodule_type
.This led to a unique_id like
2-Temperature
which was pretty obvious to be clashing with other modules.What this PR now implements:
type
field provided by the Netatmo API to distinguish between module types instead of taking an undocumented Byte from the Module address. This is used for the calculation of the Battery Status.unique_id
. So theunique_id
now looks likeXX:XX:XX:XX:XX:XX-Temperature
Example entry for
configuration.yaml
(if applicable):Checklist:
tox
. Your PR cannot be merged unless tests pass