Example #1
0
    def test_activate_scene(self, mock_put, mock_get):
        hue = HueManager()
        hue.activate_scene_in_group("Tropical twilight", "1")

        expected_url = 'http://192.168.1.23/api/your_whitelist_entry_here/groups/1/action'
        self.assertIn(mock.call(expected_url, '{"scene": "-dd2XUCmuJUipeO"}'),
                      mock_put.call_args_list)
Example #2
0
class LightsInRoomOnOffHandler(IntentHandler):

    ONOFF = "OnOff"
    ON = "On"
    OFF = "Off"
    ROOM = "Room"

    def __init__(self):
        IntentHandler.__init__(self)
        self._hue_manager = HueManager()
        room_on_off_intent_definition = self._get_room_on_off_intent_definition(
        )
        self._intent_definitions = [room_on_off_intent_definition]

    def _get_room_on_off_intent_definition(self) -> IntentDefinition:
        room_on_off = IntentDefinition("TurnLightsInRoomOnOff")

        room_names = [room.name for room in self._hue_manager.groups]
        room_parameter = SetParameter(self.ROOM,
                                      True,
                                      possible_values=room_names)

        on_off_parameter = SetParameter(self.ONOFF,
                                        True,
                                        possible_values=[self.ON, self.OFF])

        sentence_builder = SentenceBuilder()
        sentence_builder.add_string("Turn the lights in the")\
            .add_parameter(room_parameter)\
            .add_parameter(on_off_parameter)

        sentence = sentence_builder.build()
        room_on_off.add_sentence(sentence)
        return room_on_off

    def handle_intent(self, intent: Intent) -> str:
        payload = {"on": intent.parameters[self.ONOFF].lower() == "on"}
        self._hue_manager.send_room_command_to_bridge(
            intent.parameters[self.ROOM], json.dumps(payload))
        room = intent.parameters[self.ROOM]
        on_off = intent.parameters[self.ONOFF].lower()
        return "Turning the lights in the {} {}".format(room, on_off), False
Example #3
0
 def test_get_group_by_name(self, mock_get):
     hue = HueManager()
     group = hue.get_group_by_name("Kitchen")
     self.assertEqual("3", group.group_id)
Example #4
0
 def test_get_scenes(self, mock_get):
     hue = HueManager()
     mock_get.called_with(scenes_url)
     self.assertEqual(3, len(hue.scenes))
Example #5
0
 def test_get_groups(self, mock_get):
     hue = HueManager()
     mock_get.called_with(groups_url)
     self.assertEqual(3, len(hue.groups))
Example #6
0
class RoomDimmer(IntentHandler):

    UP_DOWN = "UpDown"
    UP = "Up"
    DOWN = "Down"
    IN_DECREASE = "InDecrease"
    INCREASE = "Increase"
    DECREASE = "Decrease"
    ROOM = "Room"

    def __init__(self):
        super().__init__()
        self._hue_manager = HueManager()
        dim_room_intent_definition = self.get_dim_room_intent_definition()
        self._intent_definitions = [dim_room_intent_definition]

    def get_dim_room_intent_definition(self):
        dim_room = IntentDefinition("DimRoom")

        room_names = [room.name for room in self._hue_manager.groups]
        room_parameter = SetParameter(self.ROOM,
                                      True,
                                      possible_values=room_names)
        up_down_parameter = SetParameter(self.UP_DOWN,
                                         True,
                                         possible_values=[self.UP, self.DOWN])
        in_decrease_parameter = SetParameter(
            self.IN_DECREASE,
            True,
            possible_values=[self.INCREASE, self.DECREASE])

        sentence_builder = SentenceBuilder()
        sentence_builder.add_string("Dim the lights in the")\
            .add_parameter(room_parameter)\
            .add_parameter(up_down_parameter)
        sentence = sentence_builder.build()

        sentence_builder2 = SentenceBuilder()
        sentence_builder2.add_parameter(in_decrease_parameter)\
            .add_string("the brightness in the")\
            .add_parameter(room_parameter)

        sentence2 = sentence_builder2.build()
        dim_room.add_sentence(sentence)
        dim_room.add_sentence(sentence2)

        return dim_room

    def handle_intent(self, intent: Intent) -> str:
        bri_inc = 20
        room = intent.parameters[self.ROOM]
        response = ""
        if self.UP_DOWN in intent.parameters:
            direction = intent.parameters[self.UP_DOWN]
            if intent.parameters[self.UP_DOWN] == self.DECREASE:
                bri_inc = -20
            response = "Dimming the lights in the {} {}".format(
                room, direction)

        elif self.IN_DECREASE in intent.parameters:
            action = "Increasing"
            if intent.parameters[self.IN_DECREASE] == self.DECREASE:
                bri_inc = -20
                action = "Decreasing"
            response = "{} the brightness of the lights in the {}".format(
                action, room)
        payload = {"bri_inc": bri_inc}
        self._hue_manager.send_room_command_to_bridge(
            intent.parameters[self.ROOM], json.dumps(payload))
        return response, False
Example #7
0
 def __init__(self):
     super().__init__()
     self._hue_manager = HueManager()
     dim_room_intent_definition = self.get_dim_room_intent_definition()
     self._intent_definitions = [dim_room_intent_definition]
Example #8
0
 def __init__(self):
     IntentHandler.__init__(self)
     self._hue_manager = HueManager()
     room_on_off_intent_definition = self._get_room_on_off_intent_definition(
     )
     self._intent_definitions = [room_on_off_intent_definition]