MycroftOS: Bump mycroft-enclosure-skill

This commit is contained in:
Peter Steenbergen 2020-01-15 11:46:20 +01:00
parent 7172f81018
commit 257df74090
40 changed files with 337 additions and 64 deletions

View File

@ -33,19 +33,24 @@ class MycroftOS(MycroftSkill):
super().__init__('MycroftOS')
self.skip_list = ('MycroftOS')
self.loading = True
self.airplay = self.settings.get("airplay")
self.sshd = self.settings.get("sshd")
self.airplay = self.settings.get('airplay')
self.sshd = self.settings.get('sshd')
self.spotify = self.settings.get('spotifyd')
self.btspeaker = self.settings.get('btspeaker')
self.snapclient = self.settings.get('snapclient')
self.snapserver = self.settings.get('snapserver')
self.mpd = self.settings.get('mpd')
def initialize(self):
""" Perform initalization.
Registers messagebus handlers.
"""
# Handle settings change
self.settings_change_callback = self.on_websettings_changed
try:
# Handle settings change
self.settings.set_changed_callback(self.on_websettings_changed)
self.on_websettings_changed()
# Handle the 'waking' visual
self.add_event('recognizer_loop:wakeword',
self.handle_listener_started)
@ -76,28 +81,54 @@ class MycroftOS(MycroftSkill):
#self.add_event('mycroft.volume.unduck', self.on_volume_unduck)
# Administrative messages
self.bus.on("system.shutdown", self.on_shutdown)
self.bus.on("system.reboot", self.on_reboot)
self.bus.on('system.shutdown', self.on_shutdown)
self.bus.on('system.reboot', self.on_reboot)
except Exception:
LOG.exception('In MycroftOS Skill')
def on_websettings_changed(self):
if self.sshd != self.settings.get("sshd")
if self.settings.get("sshd") is True:
self.sshd = True
enable_ssh()
if self.sshd != self.settings.get('sshd'):
if self.settings.get('sshd') is True:
self.enable_ssh()
else:
self.sshd = False
disable_ssh()
self.disable_ssh()
if self.airplay != self.settings.get("airplay")
if self.settings.get("airplay") is True:
self.airplay = True
enable_airplay()
if self.airplay != self.settings.get('airplay'):
if self.settings.get('airplay') is True:
self.enable_airplay()
else:
self.airplay = False
disable_airplay()
self.disable_airplay()
if self.spotify != self.settings.get('spotifyd'):
if self.settings.get('spotifyd') is True:
self.enable_spotify()
else:
self.disable_spotify()
if self.btspeaker != self.settings.get('btspeaker'):
if self.settings.get('btspeaker') is True:
self.enable_btspeaker()
else:
self.disable_btspeaker()
if self.snapclient != self.settings.get('snapclient'):
if self.settings.get('snapclient') is True:
self.enable_snapclient()
else:
self.disable_snapclient()
if self.snapserver != self.settings.get('snapserver'):
if self.settings.get('snapserver') is True:
self.enable_snapserver()
else:
self.disable_snapserver()
if self.mpd != self.settings.get('mpd'):
if self.settings.get('mpd') is True:
self.enable_mpd()
else:
self.disable_mpd()
# System volume
#def on_volume_set(self, message):
@ -131,19 +162,19 @@ class MycroftOS(MycroftSkill):
def on_handler_audio_start(self, message):
self.speaking = True
#framebuffer speaking visual
os.system("fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/speaking.png > /dev/null 2>&1")
os.system('fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/speaking.png > /dev/null 2>&1')
def on_handler_audio_end(self, message):
self.speaking = False
#framebuffer background
os.system("fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/background.png > /dev/null 2>&1")
os.system('fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/background.png > /dev/null 2>&1')
def on_handler_started(self, message):
handler = message.data.get('handler', '')
if self._skip_handler(handler):
return
#framebuffer thinking visual
os.system("fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/thinking.png > /dev/null 2>&1")
os.system('fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/thinking.png > /dev/null 2>&1')
def on_handler_complete(self, message):
handler = message.data.get('handler', '')
@ -154,7 +185,7 @@ class MycroftOS(MycroftSkill):
# turn off the framebuffer
if not self.speaking:
#framebuffer background
os.system("fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/background.png > /dev/null 2>&1")
os.system('fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/background.png > /dev/null 2>&1')
def _skip_handler(self, handler):
#Ignoring handlers from this skill
@ -162,15 +193,15 @@ class MycroftOS(MycroftSkill):
def handle_listener_started(self, message):
#framebuffer listen visual
os.system("fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/listen.png > /dev/null 2>&1")
os.system('fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/listen.png > /dev/null 2>&1')
def handle_listener_ended(self, message):
#framebuffer background
os.system("fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/background.png > /dev/null 2>&1")
os.system('fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/background.png > /dev/null 2>&1')
def handle_failed_stt(self, message):
#framebuffer background
os.system("fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/background.png > /dev/null 2>&1")
os.system('fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/background.png > /dev/null 2>&1')
# Device is fully started
@ -178,51 +209,219 @@ class MycroftOS(MycroftSkill):
"""Triggered after skills are initialized."""
self.loading = False
if is_paired():
os.system("fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/background.png > /dev/null 2>&1")
os.system('fbv -f -d 1 /opt/mycroft/skills/mycroftos-enclosure-skill/ui/background.png > /dev/null 2>&1')
self.speak_dialog('finished.booting')
# System actions
def on_shutdown(self, message):
self.speak("Till next time")
self.speak('Till next time')
sleep(5)
os.system("sudo halt")
os.system('sudo halt')
def on_reboot(self, message):
self.speak("I'll be right back")
self.speak('I will be right back')
sleep(5)
os.system("sudo reboot")
os.system('sudo reboot')
def enable_ssh(self):
os.system('sudo systemctl enable sshd.service')
os.system('sudo systemctl start sshd.service')
self.settings['sshd'] = True
self.sshd = True
self.speak_dialog('EnabledSSH')
def disable_ssh(self):
os.system('sudo systemctl disable sshd.service')
os.system('sudo systemctl stop sshd.service')
self.settings['sshd'] = False
self.sshd = False
self.speak_dialog('DisabledSSH')
def enable_airplay(self):
os.system('sudo systemctl enable shairport-sync.service')
os.system('sudo systemctl start shairport-sync.service')
self.settings['airplay'] = True
self.airplay = True
self.speak_dialog('EnabledAirPlay')
def disable_airplay(self):
os.system('sudo systemctl disable shairport-sync.service')
os.system('sudo systemctl stop shairport-sync.service')
self.settings['airplay'] = False
self.airplay = False
self.speak_dialog('DisabledAirPlay')
def enable_spotify(self):
os.system('sudo systemctl enable spotifyd.service')
os.system('sudo systemctl start spotifyd.service')
self.settings['spotifyd'] = True
self.spotify = True
self.speak_dialog('EnabledSpotify')
def disable_spotify(self):
os.system('sudo systemctl disable spotifyd.service')
os.system('sudo systemctl stop spotifyd.service')
self.settings['spotifyd'] = False
self.spotify = False
self.speak_dialog('DisabledSpotify')
def enable_btspeaker(self):
os.system('sudo systemctl enable btspeaker.service')
os.system('sudo systemctl start btspeaker.service')
self.settings['btspeaker'] = True
self.btspeaker = True
self.speak_dialog('EnabledBTspeaker')
def disable_btspeaker(self):
os.system('sudo systemctl disable btspeaker.service')
os.system('sudo systemctl stop btspeaker.service')
self.settings['btspeaker'] = False
self.btspeaker = False
self.speak_dialog('DisabledBTspeaker')
def enable_snapclient(self):
os.system('sudo systemctl enable snapclient.service')
os.system('sudo systemctl start snapclient.service')
self.settings['snapclient'] = True
self.snapclient = True
self.speak_dialog('EnabledSnapclient')
def disable_snapclient(self):
os.system('sudo systemctl disable snapclient.service')
os.system('sudo systemctl stop snapclient.service')
self.settings['snapclient'] = False
self.snapclient = False
self.speak_dialog('DisabledSnapclient')
def enable_snapserver(self):
os.system('sudo systemctl enable snapserver.service')
os.system('sudo systemctl start snapserver.service')
self.settings['snapserver'] = True
self.snapserver = True
self.speak_dialog('EnabledSnapserver')
def disable_snapserver(self):
os.system('sudo systemctl disable snapserver.service')
os.system('sudo systemctl stop snapserver.service')
self.settings['snapserver'] = False
self.snapserver = False
self.speak_dialog('DisabledSnapserver')
def enable_mpd(self):
os.system('sudo systemctl enable mpd.service')
os.system('sudo systemctl start mpd.service')
self.settings['mpd'] = True
self.mpd = True
self.speak_dialog('EnabledMPD')
def disable_mpd(self):
os.system('sudo systemctl disable mpd.service')
os.system('sudo systemctl stop mpd.service')
self.settings['mpd'] = False
self.mpd = False
self.speak_dialog('DisabledMPD')
# Intent handlers
@intent_file_handler("EnableSSH.intent")
def enable_ssh(self, message):
os.system("sudo systemctl enable sshd.service")
os.system("sudo systemctl start sshd.service")
self.speak_dialog("EnableSSH")
self.settings["sshd"] = True
@intent_file_handler('EnableSSH.intent')
def on_enable_ssh(self, message):
if self.sshd is False:
self.enable_ssh()
else:
self.speak_dialog('AlreadyEnabledSSH')
@intent_file_handler("DisableSSH.intent")
def disable_ssh(self, message):
os.system("sudo systemctl disable sshd.service")
os.system("sudo systemctl stop sshd.service")
self.speak_dialog("DisableSSH")
self.settings["sshd"] = False
@intent_file_handler('DisableSSH.intent')
def on_disable_ssh(self, message):
if self.sshd is True:
self.disable_ssh()
else:
self.speak_dialog('AlreadyDisabledSSH')
@intent_file_handler("EnableAirPlay.intent")
def enable_airplay(self, message):
os.system("sudo systemctl enable shairport-sync.service")
os.system("sudo systemctl start shairport-sync.service")
self.speak_dialog("EnableAirPlay")
self.settings["airplay"] = True
@intent_file_handler('EnableAirPlay.intent')
def on_enable_airplay(self, message):
if self.airplay is False:
self.enable_airplay()
else:
self.speak_dialog('AlreadyEnabledAirPlay')
@intent_file_handler("DisableAirPlay.intent")
def disable_airplay(self, message):
os.system("sudo systemctl disable shairport-sync.service")
os.system("sudo systemctl stop shairport-sync.service")
self.speak_dialog("DisableAirPlay")
self.settings["airplay"] = False
@intent_file_handler('DisableAirPlay.intent')
def on_disable_airplay(self, message):
if self.airplay is True:
self.disable_airplay()
else:
self.speak_dialog('AlreadyDisabledAirPlay')
@intent_file_handler('EnableSpotify.intent')
def on_enable_spotify(self, message):
if self.spotify is False:
self.enable_spotify()
else:
self.speak_dialog('AlreadyEnabledSpotify')
@intent_file_handler('DisableSpotify.intent')
def on_disable_spotify(self, message):
if self.spotify is True:
self.disable_spotify()
else:
self.speak_dialog('AlreadyDisabledSpotify')
@intent_file_handler('EnableBTspeaker.intent')
def on_enable_btspeaker(self, message):
if self.btspeaker is False:
self.enable_btspeaker()
else:
self.speak_dialog('AlreadyEnabledBTspeaker')
@intent_file_handler('DisableBTspeaker.intent')
def on_disable_btspeaker(self, message):
if self.btspeaker is True:
self.disable_btspeaker()
else:
self.speak_dialog('AlreadyDisabledBTspeaker')
@intent_file_handler('EnableSnapclient.intent')
def on_enable_snapclient(self, message):
if self.snapclient is False:
self.enable_snapclient()
else:
self.speak_dialog('AlreadyEnabledSnapclient')
@intent_file_handler('DisableSnapclient.intent')
def on_disable_snapclient(self, message):
if self.snapclient is True:
self.disable_snapclient()
else:
self.speak_dialog('AlreadyDisabledSnapclient')
@intent_file_handler('EnableSnapserver.intent')
def on_enable_snapserver(self, message):
if self.snapserver is False:
self.enable_snapserver()
else:
self.speak_dialog('AlreadyEnabledSnapserver')
@intent_file_handler('DisableSnapserver.intent')
def on_disable_snapserver(self, message):
if self.snapserver is True:
self.disable_snapserver()
else:
self.speak_dialog('AlreadyDisabledSnapserver')
@intent_file_handler('EnableMPD.intent')
def on_enable_mpd(self, message):
if self.mpd is False:
self.enable_mpd()
else:
self.speak_dialog('AlreadyEnabledMPD')
@intent_file_handler('DisableMPD.intent')
def on_disable_mpd(self, message):
if self.mpd is True:
self.disable_mpd()
else:
self.speak_dialog('AlreadyDisabledMPD')
def create_skill():
return MycroftOS()
return MycroftOS()

View File

@ -0,0 +1 @@
Bluetooth speaker is already stopped and disabled

View File

@ -0,0 +1 @@
Media player daemon is already stopped and disabled

View File

@ -0,0 +1 @@
Secure shell is already stopped and disabled

View File

@ -0,0 +1 @@
Snapcast client is already stopped and disabled

View File

@ -0,0 +1 @@
Snapcast server is already stopped and disabled

View File

@ -0,0 +1 @@
Spotify connect is already stopped and disabled

View File

@ -0,0 +1 @@
Bluetooth speaker is already enabled and started

View File

@ -0,0 +1 @@
Media player daemon is already enabled and started

View File

@ -0,0 +1 @@
Secure shell is already enabled and started

View File

@ -0,0 +1 @@
Snapcast client is already enabled and started

View File

@ -0,0 +1 @@
Snapcast server is already enabled and started

View File

@ -0,0 +1 @@
Spotify connect is already enabled and started

View File

@ -0,0 +1 @@
Bluetooth speaker is stopped and disabled

View File

@ -0,0 +1 @@
Media player daemon is stopped and disabled

View File

@ -0,0 +1 @@
Snapcast client is stopped and disabled

View File

@ -0,0 +1 @@
Snapcast server is stopped and disabled

View File

@ -0,0 +1 @@
Spotify connect is stopped and disabled

View File

@ -0,0 +1 @@
Bluetooth speaker is enabled and started

View File

@ -0,0 +1 @@
Media Player Daemon is enabled and started

View File

@ -0,0 +1 @@
Snapcast client is enabled and started

View File

@ -0,0 +1 @@
Snapcast server is enabled and started

View File

@ -0,0 +1 @@
Spotify connect is enabled and started

View File

@ -3,21 +3,49 @@ skillMetadata:
- name: Smart speaker functionality
fields:
- type: label
label: Smart speaker services and functionality
label: <p>You can enable or disable smart speaker services and functionality currently present on the MycroftOS system. As every user has different requirements and is using different hardware, devices and network protocols, all these services are disabled by default. You can easily enable or disable any of the below services here, by selecting the enabled checkbox (slightly delayed as you need to wait for settings synchronisation) or by using voice commands to your MycroftOS device (For example Hey Mycroft, enable spotify).</p>
- type: label
label: Airplay audio player (v1)
value: AirPlay is a proprietary protocol stack/suite developed by Apple Inc. that allows wireless streaming between devices of audio, video, device screens, and photos, together with related metadata.
label: <hr><br><strong>Airplay audio player (v1)</strong><p>AirPlay is a proprietary protocol stack/suite developed by Apple Inc. that allows wireless streaming between devices of audio, video, device screens, and photos, together with related metadata.</p>
- name: airplay
type: checkbox
label: Enabled
value: "false"
- type: label
label: <br><strong>Spotify Connect</strong><p>Make your Mycroft device available as Spotify Connect device so you can select it as possible output device from within the Spotify app. Be aware this only makes it available within the app, if you want to control spotify by voice you need to install the Spotify skill and configure it.</p>
- name: spotifyd
type: checkbox
label: Enabled
value: "false"
- type: label
label: <br><strong>Bluetooth speaker</strong><p>Make your Mycroft device available as bluetooth speaker. With this enabled you can pair your phone or other device and use your Mycroft as sound output. It should ask for a PIN, which is 0000.</p>
- name: btspeaker
type: checkbox
label: Enabled
value: "false"
- type: label
label: <br><strong>Snapcast client</strong><p>Make your Mycroft device available as Snapcast client. With this enabled you can configure your device as multiroom audio playing device. Anything played on the network via Snapcast server will be played on the device. (NOTE This still needs to be configured on an OS level through SSH and configuration files)</p>
- name: snapclient
type: checkbox
label: Enabled
value: "false"
- name: MycroftOS system configuration
fields:
- type: label
label: System services
label: <p>MycroftOS is based on a minimalistic linux OS called Buildroot. However, although small and minimalistic in size, MycroftOS comes with certain linux services and applications. This is for advanced users that would like to tinker with their box and or do more with it than only Mycroft related things.</p>
- type: label
label: Secure Shell (SSH)
value: Secure Shell (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network.[1] Typical applications include remote command-line, login, and remote command execution.
label: <hr><br><strong>Snapcast server</strong><p>Make your Mycroft device available as Snapcast server. With this enabled you can configure your device as multiroom audio device. Anything played on the device will also be forwarded to configured Snapcast client devices. (NOTE This still needs to be configured on an OS level through SSH and configuration files)</p>
- name: snapserver
type: checkbox
label: Enabled
value: "false"
- type: label
label: <br><strong>Media Player Daemon (MPD)</strong><p>Make your Mycroft device available as MPD server. With this enabled you can configure your device as Media Player Daemon device. (NOTE This still needs to be configured on an OS level through SSH and configuration files)</p>
- name: mpd
type: checkbox
label: Enabled
value: "false"
- type: label
label: <br><strong>Secure Shell (SSH)</strong><p>Secure Shell (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network.[1] Typical applications include remote command-line, login, and remote command execution.</p>
- name: sshd
type: checkbox
label: Enabled

View File

@ -0,0 +1,2 @@
Disable bluetooth
Disable blue tooth

View File

@ -0,0 +1,4 @@
Disable M P D
Disable M.P.D.
Disable MPD
Disable Media Player Daemon

View File

@ -0,0 +1,2 @@
Disable snapclient
Disable snap client

View File

@ -0,0 +1,2 @@
Disable snapserver
Disable snap server

View File

@ -0,0 +1,2 @@
Enable bluetooth
Enable blue tooth

View File

@ -0,0 +1,4 @@
Enable M P D
Enable M.P.D.
Enable MPD
Enable Media Player Daemon

View File

@ -0,0 +1,2 @@
Enable snapclient
Enable snap client

View File

@ -0,0 +1,2 @@
Enable snapserver
Enable snap server