-
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
Merged
Merged
Fix mood handling #260
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7013a72
fix mood handling (moods are always associated with groups)
Rob4t c640bf7
fix getting active mood for group
Rob4t 5bc78a0
make available moods part of a group
Rob4t bf28c0e
remove block comment
Rob4t 8badc91
add tests for moods
rgci 29945ff
fix missing whitespace and blank lines
rgci 0dfe2d6
another missing blank line in test_group
rgci d7e9d3c
fix another missing blank line and whitespace
rgci f82c1e2
re-add moods to main
Rob4t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,19 +103,20 @@ def process_result(result): | |
[ROOT_GATEWAY, ATTR_GATEWAY_INFO], | ||
process_result=process_result) | ||
|
||
def get_moods(self): | ||
def get_moods(self, group_id): | ||
""" | ||
Return moods defined on the gateway. | ||
Return moods available in given group. | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. block comment should start with '# ' |
||
#TODO check groupid | ||
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. block comment should start with '# ' |
||
|
||
def process_result(result): | ||
return [self.get_mood(mood, mood_parent=mood_parent) for mood in | ||
return [self.get_mood(mood, mood_parent=group_id) for mood in | ||
result] | ||
|
||
return Command('get', [ROOT_MOODS, mood_parent], | ||
return Command('get', [ROOT_MOODS, group_id], | ||
process_result=process_result) | ||
|
||
def get_mood(self, mood_id, *, mood_parent=None): | ||
|
@@ -124,26 +125,13 @@ def get_mood(self, mood_id, *, mood_parent=None): | |
|
||
Returns a Command. | ||
""" | ||
if mood_parent is None: | ||
mood_parent = self._get_mood_parent() | ||
|
||
def process_result(result): | ||
return Mood(result, mood_parent) | ||
|
||
return Command('get', [ROOT_MOODS, mood_parent, mood_id], | ||
mood_parent, process_result=process_result) | ||
|
||
def _get_mood_parent(self): | ||
""" | ||
Get the parent of all moods. | ||
|
||
Returns a Command. | ||
""" | ||
def process_result(result): | ||
return result[0] | ||
|
||
return Command('get', [ROOT_MOODS], process_result=process_result) | ||
|
||
def get_smart_tasks(self): | ||
""" | ||
Return the transitions linked to the gateway. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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