-
Notifications
You must be signed in to change notification settings - Fork 130
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
Fix mood handling #260
Conversation
pytradfri/gateway.py
Outdated
|
||
Returns a Command. | ||
""" | ||
mood_parent = self._get_mood_parent() | ||
#mood_parent = self._get_mood_parent() | ||
#TODO check groupid |
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.
block comment should start with '# '
pytradfri/gateway.py
Outdated
|
||
Returns a Command. | ||
""" | ||
mood_parent = self._get_mood_parent() | ||
#mood_parent = self._get_mood_parent() |
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.
block comment should start with '# '
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.
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()) |
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.
I'd like to keep this in main. Can we add try/catch instead?
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.
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)
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.
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?
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.
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
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.
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?
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.
Done. Also added the parent_id (group id) to the mood's repr
def mood(): | ||
return Mood(MOOD, 131080) | ||
|
||
def test_mood_properties(mood): |
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.
expected 2 blank lines, found 1
from pytradfri.const import ROOT_MOODS | ||
from pytradfri.mood import Mood | ||
|
||
@pytest.fixture |
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.
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): |
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.
expected 2 blank lines, found 1
|
||
@pytest.fixture |
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.
expected 2 blank lines, found 1
tests/moods.py
Outdated
'9003': 196625, | ||
'9057': 2, | ||
'9068': 1, | ||
'15013': [{'5850':1,'5851':254,'9003':65547}] |
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.
missing whitespace after ','
missing whitespace after ':'
def gateway(): | ||
return Gateway() | ||
|
||
@pytest.fixture |
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.
expected 2 blank lines, found 1
@@ -0,0 +1,9 @@ | |||
# Retrieved from Gateway running on 1.9.27 | |||
MOOD = { | |||
'9001': 'FOCUS', |
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.
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) |
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.
Black would make changes.
Thank you guys! Do you need this on pypi continue working with your implementations? |
Fixes problems with moods as described in the following issues;
#220
#106