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

Fix mood handling #260

Merged
merged 9 commits into from
Jan 4, 2020
Merged

Fix mood handling #260

merged 9 commits into from
Jan 4, 2020

Conversation

Rob4t
Copy link
Contributor

@Rob4t Rob4t commented Dec 26, 2019

Fixes problems with moods as described in the following issues;

#220
#106


Returns a Command.
"""
mood_parent = self._get_mood_parent()
#mood_parent = self._get_mood_parent()
#TODO check groupid

Choose a reason for hiding this comment

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

block comment should start with '# '


Returns a Command.
"""
mood_parent = self._get_mood_parent()
#mood_parent = self._get_mood_parent()

Choose a reason for hiding this comment

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

block comment should start with '# '

@coveralls
Copy link

coveralls commented Dec 26, 2019

Coverage Status

Coverage increased (+0.8%) to 80.708% when pulling f82c1e2 on Rob4t:master into 3f84552 on ggravlingen:master.

Copy link
Member

@ggravlingen ggravlingen left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time working on a solution! Can you please also add a test or two?

@@ -73,12 +73,6 @@
else:
print("No groups found!")
group = None
moods = api(gateway.get_moods())
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to keep this in main. Can we add try/catch instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you expect a flattened list of moods or a dict like:
{
"Group1": [ ...]
}
The former would not be very useful without the information for which group the mood is available (since there are no "global" moods)

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if that's why moods are no longer working, they might have been global when we wrote the code. The purpose of pytradfri is to reflect what data is provided by the gateway without any manipulation. Is the group included in the raw data passed by the gateway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately it is not ( see tests/moods.py ). Also the raw data of a group only has its current active mood_id.
So we have to use group.moods() to fetch the available moods for the given group

Copy link
Member

Choose a reason for hiding this comment

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

We should only return what the gateway returns, no logic nor manipulation of the data. That has to be done by the consumer in its implementation of pytradfri. That leaves us at option #1 I guess?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Also added the parent_id (group id) to the mood's repr

def mood():
return Mood(MOOD, 131080)

def test_mood_properties(mood):

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

from pytradfri.const import ROOT_MOODS
from pytradfri.mood import Mood

@pytest.fixture

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

@@ -48,3 +53,7 @@ def test_setters():
ATTR_LIGHT_COLOR_SATURATION: 200,
ATTR_LIGHT_DIMMER: 100,
}

def test_moods(group):

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1


@pytest.fixture

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

tests/moods.py Outdated
'9003': 196625,
'9057': 2,
'9068': 1,
'15013': [{'5850':1,'5851':254,'9003':65547}]

Choose a reason for hiding this comment

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

missing whitespace after ','
missing whitespace after ':'

def gateway():
return Gateway()

@pytest.fixture

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

@@ -0,0 +1,9 @@
# Retrieved from Gateway running on 1.9.27
MOOD = {
'9001': 'FOCUS',

Choose a reason for hiding this comment

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

Black would make changes.

@@ -13,4 +13,4 @@ def path(self):
return [ROOT_MOODS, self._parent, self.id]

def __repr__(self):
return '<Mood {}>'.format(self.name)
return '<Mood {} {}>'.format(self._parent, self.name)

Choose a reason for hiding this comment

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

Black would make changes.

@ggravlingen ggravlingen merged commit c0763e8 into home-assistant-libs:master Jan 4, 2020
@ggravlingen
Copy link
Member

Thank you guys! Do you need this on pypi continue working with your implementations?

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.

5 participants