def locativeHandler(request): ''' locativeHandler takes a flask request and updates the presence of a device. It retuerns a LocativeMessage. The URL of the request has to be: https://PUBLIC_ADDRESS/API/locative?ff_device=FF_DEVICE_ID&token=LOCATIVE_TOKEN ''' message = LocativeMessage(request) logging.debug('locative: got message from {} presence: {}'.format(message.ffDevice, message.presence)) if message.presence: ffScheduler.cancel(message.jobID) ffCommand(message.ffDevice, {'presence': message.presence}, source='Locative Presence API') else: ffScheduler.runInM(5, delayedUpdatePresence, args=[message], job_id=message.jobID) return message
def apiCommand(): c = request.get_json(force=True) logging.critical(str(c)) command = c.get("command") logging.critical(command) device = c.get("device") force = c.get("force") routine = c.get("routine") source = "web: /API/command" if routine: ffCommand(device, command, routine=routine, force=force, source=source) else: ffCommand(device, command, source=source) # Refresh device views on change on UI device_views.refreshViews() return "OK"
def apiCommand(): c = request.get_json(force=True) logging.critical(str(c)) command = c.get('command') logging.critical(command) device = c.get('device') force = c.get('force') routine = c.get('routine') source = 'web: /API/command' if routine: ffCommand(device, command, routine=routine, force=force, source=source) else: ffCommand(device, command, source=source) # Refresh device views on change on UI device_views.refreshViews() return "OK"
def echo_change_mode(intent): routine_list = getRoutineList() mode = intent.get('slots').get('mode').get('value').lower() close_matches = difflib.get_close_matches(mode, routine_list) if len(close_matches) > 0: routine = close_matches[0] myCommand = ffCommand(routine, None, routine=True, source="Echo command", force=True) if myCommand.result: return make_response("Changed mode to " + str(routine), "Changed mode to " + str(routine)) return make_response("Error changing mode to " + str(mode), "Error changing mode to " + str(mode), card_title="Firefly Smart Home Error")
def ifttt_change_mode(request): routine_list = getRoutineList() mode = request.get('mode').lower() if mode is None: return False close_matches = difflib.get_close_matches(mode, routine_list) if len(close_matches) > 0: routine = close_matches[0] myCommand = ffCommand(routine, None, routine=True, source="IFTTT command", force=True) if myCommand.result: return True return False
def ifttt_switch(request): device_list = getDeviceList() device = request.get('device').lower() if device is None: return False state = request.get('state') close_matches = difflib.get_close_matches(device, device_list.keys()) if len(close_matches) > 0: device = close_matches[0] myCommand = ffCommand(device_list.get(device), { 'switch': state}, source="IFTTT command") if myCommand.result: return True return False
def ifttt_switch(request): device_list = getDeviceList() device = request.get('device').lower() if device is None: return False state = request.get('state') close_matches = difflib.get_close_matches(device, device_list.keys()) if len(close_matches) > 0: device = close_matches[0] myCommand = ffCommand(device_list.get(device), {'switch': state}, source="IFTTT command") if myCommand.result: return True return False
def echo_switch(intent): device_list = getDeviceList() device = intent.get('slots').get('device').get('value').lower() state = intent.get('slots').get('state').get('value') close_matches = difflib.get_close_matches(device, device_list.keys()) logging.critical(device_list) logging.critical(close_matches) if len(close_matches) > 0: device = close_matches[0] myCommand = ffCommand(device_list.get(device), {'switch':state}) if myCommand.result: return make_response("Turned " + str(device) + " " + str(state), "Turned " + str(device) + " " + str(state)) return make_response("Error finding device " + str(device), "Error finding device " + str(device), card_title="Firefly Smart Home Error")
def echo_dimmer(intent): device_list = getDeviceList() device = intent.get('slots').get('device').get('value').lower() level = int(intent.get('slots').get('level').get('value')) close_matches = difflib.get_close_matches(device, device_list.keys()) if len(close_matches) < 1: get_device_list() close_matches = difflib.get_close_matches(device, device_list.keys()) if len(close_matches) > 0: device = close_matches[0] myCommand = ffCommand(device_list.get(device), {'setLight' : {'level':level}}) if myCommand.result: return make_response("Set " + str(device) + " to " + str(level) + " percent.", "Set " + str(device) + " to " + str(level) + "percent.") return make_response("Error finding device " + str(device), "Error finding device " + str(device), card_title="Firefly Smart Home Error")
def echo_switch(intent): device_list = getDeviceList() device = intent.get('slots').get('device').get('value').lower() state = intent.get('slots').get('state').get('value') close_matches = difflib.get_close_matches(device, device_list.keys()) logging.critical(device_list) logging.critical(close_matches) if len(close_matches) > 0: device = close_matches[0] myCommand = ffCommand(device_list.get(device), {'switch': state}) if myCommand.result: return make_response("Turned " + str(device) + " " + str(state), "Turned " + str(device) + " " + str(state)) return make_response("Error finding device " + str(device), "Error finding device " + str(device), card_title="Firefly Smart Home Error")
def echo_dimmer(intent): device_list = getDeviceList() device = intent.get('slots').get('device').get('value').lower() level = int(intent.get('slots').get('level').get('value')) close_matches = difflib.get_close_matches(device, device_list.keys()) if len(close_matches) < 1: get_device_list() close_matches = difflib.get_close_matches(device, device_list.keys()) if len(close_matches) > 0: device = close_matches[0] myCommand = ffCommand(device_list.get(device), {'setLight': { 'level': level }}) if myCommand.result: return make_response( "Set " + str(device) + " to " + str(level) + " percent.", "Set " + str(device) + " to " + str(level) + "percent.") return make_response("Error finding device " + str(device), "Error finding device " + str(device), card_title="Firefly Smart Home Error")
def send_all(self): for device in deviceDB.find({"config.subType": "notification"}): dID = device.get('id') ffCommand(str(dID), {'notify': {'message': self._message}}) if config.get_boolean('SPEECH', 'enable'): self.send_cast(config.get_item('SPEECH', 'default_device').lower())
def send(self): notificationEvent = ffCommand(self._deviceID, {'notify': {'message' :self._message}})
def send_all(self): for device in deviceDB.find({"config.subType":"notification"}): dID = device.get('id') notificationEvent = ffCommand(str(dID), {'notify': {'message' :self._message}})
def ha_bridge_off(p_request): ffCommand(p_request.get('device'), {'switch': 'off'}, source='HA Bridge') return ""
def ha_bridge_dim(p_request): ffCommand(p_request.get('device'), {'setLight' : {'level':p_request.get('level')}}, source='HA Bridge') return ""
def send(self): ffCommand(self._deviceID, {'notify': {'message': self._message}})
def delayedUpdatePresence(message): ffCommand(message.ffDevice, {'presence': message.presence}, source='Locative Presence API')