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

Complying to #65 - reading parameters of different bulbs types #67

Merged
merged 8 commits into from
Oct 19, 2017

Conversation

matemaciek
Copy link
Contributor

No description provided.

raw_color = self.raw.get(ATTR_LIGHT_COLOR)
if raw_color is not None and len(raw_color) == 6:
return raw_color
(x, y) = self.xy_color
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if I'm 100% happy with this.

This property used to be a direct 1:1 mapping with the underlying data from the API. I think that it should stay like that. If we want to offer smarter things on top, maybe we can offer it as a utility function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's true for all hex_color, xy_color and kelvin_color. Maybe each of them need to have two flavours - "raw" and "best guess"? Maybe boolean parameter? Than it can default to one of flavours - which one you'd think would be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, they're properties, so it conflicts with parametrizing them. So two sets of properties maybe? [hex|xy|kelvin]_color_[raw|guess]? Or [hex|xy|kelvin]_color[_best_guess], or even [hex|xy|kelvin]_color[_raw]. I also don't have a good suffix for this new property - guess, best_guess, estimate? Neither captures exact behaviour, which is "If I have a value from API, return it, else estimate from other values from API".

Copy link
Member

Choose a reason for hiding this comment

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

Are you not talking about something along the line of an inferred value?
https://en.wikipedia.org/wiki/Inference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, inference is the word, thanks! So how do you find a set of properties: [hex|xy|kelvin]_color_[raw|inferred]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But then we have inconsistency in kelvin_color, which is definitely inferred. And this change would be breaking because homeassistant checks bulb features by verifing if hex_color makes sense? So maybe it would be good to introduce breaking change, together with can_set_, to introduce more order? I'll then add can_set_ to this PR soon.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Breaking with Home Assistant is fine as HASS uses pinned requirements. If we messed up with kelvin_color, let's fix it.

Copy link
Contributor Author

@matemaciek matemaciek Oct 16, 2017

Choose a reason for hiding this comment

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

OK, so which convention should we follow:

  1. [hex|xy]_color[_raw] and kelvin_color
  2. [hex|xy]_color[_inferred] and kelvin_color_inferred
  3. [hex|xy]_color_[raw|inferred] and kelvin_color_inferred

? (My order from most to least preferred: 1, 3, 2)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't follow your convention list. This is what I would prefer:

  • I want, by default, property names to reflect what is returned from the API. xy_color comes directly from the returned dictionary. If we don't do this, the user can no longer trust if some data is there or that we're trying to come up with an answer, which might not fit their use case
  • I want the property name to reflect if we're doing magic to make it work. So add _inferred.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, so what's you're describing is I guess 2) [hex|xy]_color[_inferred] and kelvin_color_inferred. which means 5 properties:

  • hex_color,
  • xy_color,
  • hex_color_inferred,
  • xy_color_inferred,
  • kelvin_color_inferred.
    I'll change properties name that way.

@matemaciek
Copy link
Contributor Author

I went with [hex|xy]_color[_raw] and kelvin_color. Advantages:

  • if user knows that he wants raw value, he explicitely asks for it.
  • if user just want the value, we're doing the best we can; even if lightbulb has one fixed color, this color has some temperature, although it doesn't inform about it via API
  • we're backward compatible

@ggravlingen
Copy link
Member

Guess we're good to merge here? @balloob

@ggravlingen ggravlingen merged commit 10ff910 into home-assistant-libs:master Oct 19, 2017
@ggravlingen
Copy link
Member

Merged and pushed to pypi as 3.0.1. Thanks @matemaciek for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants