def get_humidity(self, entities):
     original_item_label = entities["HumidityLabel"]["entity_original_value"]
     item_label = entities["HumidityLabel"]["entity_value"]
     item_name = oh.get_item_name_by_label(original_item_label, "CurrentHumidity")
     item_state = oh.get_item_state(item_name)
     text = self._sentence("{} % ".format(item_state))
     return Notification(text=text)
 def get_brightness(self, entities):
     original_item_label = entities["BrightnessLabel"]["entity_original_value"]
     item_label = entities["BrightnessLabel"]["entity_value"]
     item_name = oh.get_item_name_by_label(original_item_label, "CurrentBrightness")
     item_state = oh.get_item_state(item_name)
     text = self._sentence("{} lux".format(item_state))
     return Notification(text=text)
Exemple #3
0
 def update_metadata(song=None, artist=None, img=None):
     """
     Updates artist and song labels on UI
     """
     ApplicationWindow.builder.get_object('song').set_text(song)
     ApplicationWindow.builder.get_object('artist').set_text(artist)
     notification = Notification()
     notification.send(song, artist)
    def get_temperature(self, entities):
        original_item_label = entities["TemperatureLabel"]["entity_original_value"]
        item_label = entities["TemperatureLabel"]["entity_value"]

        item_name = oh.get_item_name_by_label(original_item_label, "CurrentTemperature")
        item_state = oh.get_item_state(item_name)
        text = self._sentence("{} degrees ".format(item_state))
        return Notification(text=text)
 def change_language(self, entities):
     new_lang = entities["Language"]["entity_value"]
     new_original_lang = entities["Language"]["entity_original_value"]
     text = self._sentence("Switching language to {}".format(new_original_lang))
     notification = Notification(text=text)
     import threading
     topic = "mayordomo/configuration/language/set"
     threading.Timer(2, mqtt_handler.publish, [topic, self.mapping[new_original_lang]]).start()
     return notification
    def set_device_state(self, entities):
        original_item_label = entities["SwitchableOnOffLabel"]["entity_original_value"]
        item_label = entities["SwitchableOnOffLabel"]["entity_value"]
        original_new_state = entities["OnOffAction"]["entity_original_value"]

        item_name = oh.get_item_name_by_label(original_item_label, "Switchable")
        oh.send_command(item_name, self.on_off_mapping[original_new_state])
        text = self._sentence("{} turned {}".format(item_label, self.on_off_mapping[original_new_state]))
        return Notification(text=text)
    def set_light_color(self, entities):
        original_item_label = entities["LightColorLabel"]["entity_original_value"]
        item_label = entities["LightColorLabel"]["entity_value"]
        original_new_color = entities["ColorValue"]["entity_original_value"]

        item_name = oh.get_item_name_by_label(original_item_label, "Lighting")
        oh.send_command(item_name, self.color_mapping.get(original_new_color))
        text = self._sentence("{} light {}".format(item_label, original_new_color))
        return Notification(text=text)
    def set_shutter_level(self, entities):
        original_item_label = entities["ShutterLabel"]["entity_original_value"]
        item_label = entities["ShutterLabel"]["entity_value"]
        action = entities["PullUpDownAction"]["entity_original_value"]
        item_name = oh.get_item_name_by_label(original_item_label, "Rollershutter")

        if "PercentageValue" in entities:
            new_item_state = entities["PercentageValue"]
            if "%" in new_item_state:
                new_item_state = new_item_state.replace("%", "")
            oh.send_command(item_name, new_item_state)
        else:
            new_item_state = "ok"
            oh.send_command(item_name, self.pull_up_down_mapping[action])
        text = self._sentence("{} blinds at {} percent".format(item_label, new_item_state))
        return Notification(text=text)
    def set_light_level(self, entities):
        original_item_label = entities["LightDimLabel"]["entity_original_value"]
        item_label = entities["LightDimLabel"]["entity_value"]
        action = entities["IncreaseDecreaseAction"]["entity_original_value"]
        item_name = oh.get_item_name_by_label(original_item_label, "Lighting")

        item_state_ = oh.get_item_state(item_name)
        item_state = float(item_state_.split(",")[1]) if "," in item_state_ else float(item_state_)
        if "PercentageValue" in entities:
            new_item_state = entities["PercentageValue"]
            if "%" in new_item_state:
                new_item_state = new_item_state.replace("%", "")
        else:
            new_item_state = item_state + 10 if action == "increase" else item_state - 10
            new_item_state = sorted((0, new_item_state, 100))[1]
        oh.send_command(item_name, new_item_state)
        text = self._sentence("{} light at {} percent".format(item_label, new_item_state))
        return Notification(text=text)
Exemple #10
0
 def _make_notification(self, id: str, title: str, detail: str):
     return Notification(self.id, id, title, detail)
 def greet_person(self, entities):
     person_name = entities["Person"]["entity_value"]
     text = self._sentence("Hello {}, how are you?".format(person_name))
     notification = Notification(text=text)
     return notification
def handle_message(mosq, obj, msg):
    start_time = time.time()
    logger.debug("TOPIC: {}; MESSAGE: {}".format(msg.topic,
                                                 msg.payload.decode('utf-8')))
    try:
        payload = json.loads(msg.payload)
        utterance = payload["message"]
        device_name = payload["device_name"]
        user_name = payload["user_name"]
        logger.info("New request by {} from {}: {}".format(
            user_name, device_name, utterance))
    except KeyError:
        logger.error("Incorrect utterance message: {}".format(msg.payload))
        return
    except ValueError:
        logger.error("Incorrect utterance message: {}".format(msg.payload))
        return

    try:
        device = devices_handler.get_device(device_name)
    except AttributeError:
        logger.error("Device '{}' is not registered, aborting message".format(
            device_name))
        return

    user_session = session_handler.get_user_session(user_name)
    utterance_lemmas = nlp_providers_handler.get_sentence_lemmas(utterance)
    logger.debug("Request lemma: {}".format(utterance_lemmas))

    final_intent = None
    for final_intent in engine_handler.determine_intent(
            utterance_lemmas,
            context_manager=user_session.get_context_manager()):
        pass

    logger.debug("The final intent is: {}".format(final_intent))
    if not final_intent:
        answer = Notification("Error", "Error")
        device.send_answer(answer.to_json())
        return

    for category, entity in final_intent["entities"].iteritems():
        metadata = engine_handler.get_entity_metadata(entity)
        user_session.inject_context({
            'data': [(entity, category, metadata)],
            'key': entity,
            'confidence': 0.75
        })

    for required_tag in final_intent["missing_required_tag"]:
        try:
            entity_category_info = engine_handler.get_entity_metadata(
                required_tag, True)
            text = entity_category_info.get("missing_phrase")
            answer = Notification("Pregunta", text, category="question")
        except ValueError:
            answer = Notification("Error", "Error processing the command")
        device.send_answer(answer.to_json())
        break
    else:
        for category, entity in final_intent["entities"].iteritems():
            metadata = engine_handler.get_entity_metadata(entity, True)
            if metadata:
                final_intent["entities"][
                    category] = engine_handler.get_entity_metadata(
                        entity, True)
            else:
                final_intent["entities"][category] = entity
        answer = plugins_handler.handle_intent(final_intent)
        if answer is None:
            answer = Notification("Error",
                                  "I don't know how to do that",
                                  category="answer")
        device.send_answer(answer.to_json())
    logger.debug("Time to process the utterance message: {} seconds".format(
        time.time() - start_time))