-
Notifications
You must be signed in to change notification settings - Fork 227
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] Fix security issue by upgrading ansible version #598
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
Update the volume | ||
|
||
## Input parameters | ||
|
||
| parameter | required | type | default | choices | comment | | ||
|:----------|:---------|:-------|:--------|:----------------|:-----------------------------------------------------------------------------------| | ||
| level | yes | int | None | | The volume level to set or increase or decrease depending of the selected 'action' | | ||
| action | no | string | set | set,raise,lower | The action to apply to the volume | | ||
|
||
Action type: | ||
|
||
- **set:** set the 'level' value as new volume level | ||
- **raise:** increase the current volume level with the value provided in 'level' | ||
- **lower:** decrease the current volume level with the value provided in 'level' | ||
|
||
## Returned values | ||
|
||
| name | description | type | sample | | ||
|:--------------|:---------------------------------------|:-------|:-------| | ||
| asked_level | The level variable sent to the neuron | int | 22 | | ||
| asked_action | The action variable sent to the neuron | string | set | | ||
| current_level | The current volume level on the system | int | 50 | | ||
|
||
|
||
## Synapses example | ||
|
||
Set the volume to 50% | ||
```yaml | ||
- name: "set-volume" | ||
signals: | ||
- order: "set the volume to 50" | ||
neurons: | ||
- volume: | ||
level: "50" | ||
``` | ||
Set the volume dynamically | ||
```yaml | ||
- name: "set-volume-dynamic" | ||
signals: | ||
- order: "set the volume to {{ volume }}" | ||
neurons: | ||
- volume: | ||
level: "{{ volume }}" | ||
``` | ||
>**Note:** Depending of your STT engine, the caught 'volume' variable can be a string. For example "twenty" instead of "20". | ||
Raise the volume | ||
```yaml | ||
- name: "raise-volume" | ||
signals: | ||
- order: "raise the volume" | ||
neurons: | ||
- volume: | ||
level: "10" | ||
action: "raise" | ||
``` | ||
Reduce the volume | ||
```yaml | ||
- name: "lower-volume" | ||
signals: | ||
- order: "reduce the volume" | ||
neurons: | ||
- volume: | ||
level: "10" | ||
action: "lower" | ||
``` |
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import logging | ||
|
||
from kalliope.core import NeuronModule | ||
import alsaaudio | ||
|
||
from kalliope.core.NeuronModule import InvalidParameterException | ||
|
||
logging.basicConfig() | ||
logger = logging.getLogger("kalliope") | ||
|
||
|
||
class SoundManager(object): | ||
|
||
try: | ||
m = alsaaudio.Mixer() | ||
except alsaaudio.ALSAAudioError: | ||
# no master, we are on a Rpi | ||
try: | ||
m = alsaaudio.Mixer("PCM") | ||
except alsaaudio.ALSAAudioError: | ||
# no audio config at all | ||
m = None | ||
|
||
@classmethod | ||
def set_volume(cls, volume_level): | ||
if cls.m is not None: | ||
cls.m.setvolume(int(volume_level)) | ||
|
||
@classmethod | ||
def get_volume(cls): | ||
if cls.m is not None: | ||
vol = cls.m.getvolume() | ||
return int(vol[0]) | ||
return None | ||
|
||
|
||
class Volume(NeuronModule): | ||
|
||
def __init__(self, **kwargs): | ||
super(Volume, self).__init__(**kwargs) | ||
|
||
self.level = kwargs.get('level', None) | ||
self.action = kwargs.get('action', "set") # can be set, raise or lower | ||
|
||
# check parameters | ||
if self._is_parameters_ok(): | ||
if self.action == "set": | ||
logger.debug("[Volume] set volume to: {}".format(self.level)) | ||
SoundManager.set_volume(self.level) | ||
if self.action == "raise": | ||
current_level = SoundManager.get_volume() | ||
level_to_set = self.level + current_level | ||
if level_to_set > 100: | ||
level_to_set = 100 | ||
logger.debug("[Volume] set volume to: {}".format(level_to_set)) | ||
SoundManager.set_volume(level_to_set) | ||
if self.action == "lower": | ||
current_level = SoundManager.get_volume() | ||
level_to_set = self.level - current_level | ||
if level_to_set < 0: | ||
level_to_set = 0 | ||
logger.debug("[Volume] set volume to: {}".format(level_to_set)) | ||
SoundManager.set_volume(level_to_set) | ||
|
||
message = { | ||
"asked_level": self.level, | ||
"asked_action": self.action, | ||
"current_level": SoundManager.get_volume() | ||
} | ||
self.say(message) | ||
|
||
def _is_parameters_ok(self): | ||
if self.level is None: | ||
raise InvalidParameterException("[Volume] level need to be set") | ||
try: | ||
self.level = int(self.level) | ||
except ValueError: | ||
raise InvalidParameterException("[Volume] level '{}' is not a valid integer".format(self.level)) | ||
if self.level < 0 or self.level > 100: | ||
raise InvalidParameterException("[Volume] level need to be placed between 0 and 100") | ||
if self.action not in ["set", "raise", "lower"]: | ||
raise InvalidParameterException("[Volume] action can be 'set', 'raise' or 'lower'") | ||
return True |
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
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.
Level expects an
int
and the default value isNone
. it can lead to type incompatibility in the next linesm such asself.level - current_level
.Maybe we could replace the default value to
0
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.
Sorry i merged before answering. I saw that you approved.
Anyway, the level is tested in the method below. It will fail if it's not an integer. And this parameter is mandatory.