diff --git a/__init__.py b/__init__.py index 3d95be0..4f99732 100644 --- a/__init__.py +++ b/__init__.py @@ -69,16 +69,51 @@ """ return self.settings.get("log_level", "INFO") + @intent_handler("PairLights.intent"): + def handle_pair_lights_intent(self, message): + if not os.path.exists('/dev/ttyUSB0'): + self.speak_dialog("bridge.not.connected") + return + with Serial(port='/dev/ttyUSB0', baudrate=115200) as s: + s.write('s30\n'.encode()) + self.speak_dialog("pair.lights") + + @intent_handler("ClearLights.intent"): + def handle_clear_lights_intent(self, messages): + if not os.path.exists('/dev/ttyUSB0'): + self.speak_dialog("bridge.not.connected") + return + with Serial(port='/dev/ttyUSB0', baudrate=115200) as s: + s.write('a\n'.encode()) + self.speak_dialog("clear.lights") + @intent_handler("LightsOn.intent") def handle_lights_on_intent(self, message): - if os.path.exists('/dev/ttyUSB0'): + if not os.path.exists('/dev/ttyUSB0'): + self.speak_dialog("bridge.not.connected") + return + light = message.data.get('light') + if light is None: with Serial(port='/dev/ttyUSB0', baudrate=115200) as s: - s.write('p0,0,3\nw0\n'.encode()) + s.write('p1,0,3\nw1\n'.encode()) + if light == 'rainbow': + with Serial(port='/dev/ttyUSB0', baudrate=115200) as s: + s.write('p1,0,0\nw1\n'.encode()) + else: + with Serial(port='/dev/ttyUSB0', baudrate=115200) as s: + s.write('p0,0,3\nw1\n'.encode()) self.speak_dialog("lights.on") @intent_handler("LightsOff.intent") def handle_lights_off_intent(self, message): - if os.path.exists('/dev/ttyUSB0'): + if not os.path.exists('/dev/ttyUSB0'): + self.speak_dialog("bridge_not_connected") + return + light = message.data.get('light') + if light is None: + with Serial(port='/dev/ttyUSB0', baudrate=115200) as s: + s.write('z1\n'.encode()) + else: with Serial(port='/dev/ttyUSB0', baudrate=115200) as s: s.write('z0\n'.encode()) self.speak_dialog("lights.off") diff --git a/locale/en-us/dialog/bridge.not.connected.dialog b/locale/en-us/dialog/bridge.not.connected.dialog new file mode 100644 index 0000000..4add027 --- /dev/null +++ b/locale/en-us/dialog/bridge.not.connected.dialog @@ -0,0 +1,2 @@ +Flowtoys Connect Bridge not found +Check the Flowtoys Connect Bridge diff --git a/locale/en-us/dialog/clear.lights.dialog b/locale/en-us/dialog/clear.lights.dialog new file mode 100644 index 0000000..10e4509 --- /dev/null +++ b/locale/en-us/dialog/clear.lights.dialog @@ -0,0 +1,2 @@ +cleared all flowtoys light groups +unpaired all flowtoys diff --git a/locale/en-us/dialog/pair.lights.dialog b/locale/en-us/dialog/pair.lights.dialog new file mode 100644 index 0000000..c5638d0 --- /dev/null +++ b/locale/en-us/dialog/pair.lights.dialog @@ -0,0 +1 @@ +pairing started for 1 minute. set your props to private groups. then select page 2 mode 1 on a prop in each group to pair its group. diff --git a/locale/en-us/intents/ClearLights.intent b/locale/en-us/intents/ClearLights.intent new file mode 100644 index 0000000..d5bb62f --- /dev/null +++ b/locale/en-us/intents/ClearLights.intent @@ -0,0 +1 @@ +(clear | reset) (light | flowtoy) (pairs | groups) diff --git a/locale/en-us/intents/LightsOff.intent b/locale/en-us/intents/LightsOff.intent index 584e24f..d41b145 100644 --- a/locale/en-us/intents/LightsOff.intent +++ b/locale/en-us/intents/LightsOff.intent @@ -1,4 +1,15 @@ -turn off the lights -turn off the light -lights off -light off +turn off the (light | lights) +:0 turn off the (light | lights) +:0 :0 turn off the (light | lights) +(light | lights) off +:0 (light | lights) off +:0 :0 (light | lights) off +turn off the {light} (light | lights) +:0 turn off the {light} (light | lights) +:0 :0 turn off the {light} (light | lights) +{light} (light | lights) off +:0 {light} (light | lights) off +:0 :0 {light} (light | lights) off +{light} off +:0 {light} off +:0 :0 {light} off diff --git a/locale/en-us/intents/LightsOn.intent b/locale/en-us/intents/LightsOn.intent index d95c405..a4d1474 100644 --- a/locale/en-us/intents/LightsOn.intent +++ b/locale/en-us/intents/LightsOn.intent @@ -1,4 +1,15 @@ -turn on the lights -turn on the light -lights on -light on +turn on the (light | lights) +:0 turn on the (light | lights) +:0 :0 turn on the (light | lights) +(light | lights) on +:0 (light | lights) on +:0 :0 (light | lights) on +turn on the {light} (light | lights) +:0 turn on the {light} (light | lights) +:0 :0 turn on the {light} (light | lights) +{light} (light | lights) on +:0 {light} (light | lights) on +:0 :0 {light} (light | lights) on +{light} on +:0 {light} on +:0 :0 {light} on diff --git a/locale/en-us/intents/PairLights.intent b/locale/en-us/intents/PairLights.intent new file mode 100644 index 0000000..2e11a44 --- /dev/null +++ b/locale/en-us/intents/PairLights.intent @@ -0,0 +1,6 @@ +pair lights +pair flowtoys +begin pairing lights +begin pairing flowtoys +start pairing lights +start pairing flowtoys