Skip to content
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

Add hash magic method to driver, controller, nodes and values #134

Merged
merged 6 commits into from Feb 23, 2021

Conversation

raman325
Copy link
Contributor

As part of this discussion: home-assistant/core#46673 (comment) we realized that our representation for various models is not unique enough. This make controller, node, and value representations unique so they can be usefully hashed.

Without this, you cannot use the zwave_js.set_config_parameter on entities from two different config entries with the same node ID

@marcelveldt
Copy link
Contributor

marcelveldt commented Feb 23, 2021

Shouldn't you be adding a hash method for this ?

def __hash__(self):
    return hash(homeid, nodeid)

@MartinHjelmare
Copy link
Contributor

The default hash for custom objects isn't based on __repr__ but this PR may still be a good improvement.

@raman325
Copy link
Contributor Author

Shouldn't you be adding a hash method for this ?

def __hash__(self):
    return hash(homeid, nodeid)

OK so keep the representation as is and just improve the hash?

@marcelveldt
Copy link
Contributor

marcelveldt commented Feb 23, 2021

I think that is better, future wise but like @MartinHjelmare said there is no direct issue atm.

@MartinHjelmare
Copy link
Contributor

MartinHjelmare commented Feb 23, 2021

If we always reload the complete state when starting the listen, is there a case when the nodes' native instance id won't be unique?

@marcelveldt
Copy link
Contributor

marcelveldt commented Feb 23, 2021

I think it could only be an issue if we instantiate Z-Wave Nodes from the model not driven by the controller logic like for compare actions or something like that. Better be safe than sorry and add in the small hash method, creating the hash based on home id and node id and it's all good.

@raman325
Copy link
Contributor Author

so hash has been added, revert repr changes or no?

Copy link
Contributor

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@MartinHjelmare MartinHjelmare changed the title Add repr for controller, include controller in node repr, and include node in value repr Add hash magic method to driver, controller, nodes and values Feb 23, 2021
@MartinHjelmare MartinHjelmare merged commit 482980c into home-assistant-libs:master Feb 23, 2021
@raman325 raman325 deleted the value_repr branch February 23, 2021 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants