Skip to content

Adding helper for get and set values#5743

Merged
turbokongen merged 6 commits into
home-assistant:devfrom
turbokongen:zwave-get-value
Feb 9, 2017
Merged

Adding helper for get and set values#5743
turbokongen merged 6 commits into
home-assistant:devfrom
turbokongen:zwave-get-value

Conversation

@turbokongen
Copy link
Copy Markdown
Contributor

Description:
Ref: #5619 (review)
I'm not sure if this is any helpful at all, only gaining 6 less lines of code.
Discussion open :)

@mention-bot
Copy link
Copy Markdown

@turbokongen, thanks for your PR! By analyzing the history of the files in this pull request, we identified @devdelay, @armills and @leoc to be potential reviewers.

@emlove
Copy link
Copy Markdown
Contributor

emlove commented Feb 4, 2017

I think this is better than what's there right now, but I'm going to use this as a discussion for a further refactoring I've been mulling over for a while. The root use-case for these loops are Entities that need to reference more than one ZWave Value. Currently, entities are tied to one value, which is passed in when the entity is created.

Right now we're looping over all the node values every time a different value needs to be looked up. The way I'd ultimately like to implement this is to refactor the discovery code to search for all the values that an entity needs. Right now in DISCOVERY_COMPONENTS, each item is a description of one ZWave value that will trigger the creation of the underlying entity. I think we could come up with a way to expand these definitions to include additional values that should also be passed to the entity if they are discovered on the network. I implemented something of a first-pass at this for ZWave color lights, but this should be generalized in the ZWave component code.

This way the ZWave entities will get a reference to the extra values they need as soon as its discovered by the ZWave network, and they won't need to do the search each time they need it.

Comment thread homeassistant/components/light/zwave.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

member should be dropped here, since it's expecting a reference to the Value object.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So this is expecting the object, and not the value.data?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My preference would be to make this an internal method, and add wrapper functions get_value and set_value. I think it's quicker to read and understand self.get_value/self.set_value in the code instead of self.value_handler.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That was my initial thought, but since the code is nearly the same for both, I found it better to have an argument.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I just mean something small like this, just to make it easier to read, but still keeping all the code common. Up to you, though.

def get_value(**kwargs)
    return self._value_handler(method='get', **kwargs)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't think of it that way :)
I will do that. 👍

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

Comment thread homeassistant/components/cover/zwave.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This was releasing either the 'Open' or 'Down' button

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wasn't clear: Previously it was releasing both buttons: Open for open and Down for close (maybe should have released all 4 names).

But now you are only releasing _open, so I would expect stop_cover not to work while the cover is closing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The way the releasbutton command in OZW works is not like the naming would suggest.
releasebutton triggers a stop command, and pressbutton triggers a start command.

https://github.com/OpenZWave/open-zwave/blob/master/cpp/src/Manager.cpp#L3028

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also, before I had Open or Down as stop alternatives, because it would work on either type of devices regardless if they had Open, Close or Up, Down label pairs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are you saying the ID doesn't matter?
value->ReleaseButton is called on a specific ID.

I don't have a cover device to test this. Does this work for you for stopping both open & close movement?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't have a cover device either, but yes. Calling the release button on either open,close or up,down labels will stop the level change. That is how the old code was made. 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why did you drop the rounding?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changes must have been made to OZW since I made the HVAC/climate component. Then it was not working without rounding. Now it responds perfectly to the set .5 intervals.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you drop the temperature rounding on purpose?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@turbokongen
Copy link
Copy Markdown
Contributor Author

The last committ, I need somebody to test if that really works, as this is just based on how I read the code.

@andrey-git
Copy link
Copy Markdown
Contributor

@turbokongen I don't have a cover device :(

@fabaff fabaff changed the title [WIP][zwave]Adding helper for get and set values Adding helper for get and set values Feb 8, 2017
Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

🐬 ok to merge when you have resolved the conflicts.

@balloob
Copy link
Copy Markdown
Member

balloob commented Feb 9, 2017

@armills I like that idea, should we move that discussion to an issue?

@emlove
Copy link
Copy Markdown
Contributor

emlove commented Feb 9, 2017

@balloob I'll probably just open a PR at some point with at least a proof of concept, and we can discuss it there.

@turbokongen turbokongen merged commit 298575f into home-assistant:dev Feb 9, 2017
@home-assistant home-assistant locked and limited conversation to collaborators May 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants