-
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
Changes from 5 commits
7013a72
c640bf7
5bc78a0
bf28c0e
8badc91
29945ff
0dfe2d6
d7e9d3c
f82c1e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Black would make changes. |
||
'9002': 1577189497, | ||
'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 commentThe reason will be displayed to describe this comment to others. Learn more. missing whitespace after ',' |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,19 @@ | |
ATTR_LIGHT_MIREDS, | ||
ATTR_LIGHT_COLOR_HUE, | ||
ATTR_LIGHT_COLOR_SATURATION, | ||
ATTR_LIGHT_DIMMER | ||
ATTR_LIGHT_DIMMER, | ||
ROOT_MOODS | ||
) | ||
from pytradfri.group import Group | ||
from pytradfri.gateway import Gateway | ||
|
||
@pytest.fixture | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
def gateway(): | ||
return Gateway() | ||
|
||
@pytest.fixture | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
def group(): | ||
return Group(GROUP) | ||
def group(gateway): | ||
return Group(gateway, GROUP) | ||
|
||
|
||
def test_setters(): | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
cmd = group.moods() | ||
assert cmd.path == [ROOT_MOODS, group.id] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
from moods import MOOD | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
def mood(): | ||
return Mood(MOOD, 131080) | ||
|
||
def test_mood_properties(mood): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
assert mood.path == [ROOT_MOODS, 131080, 196625] |
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