Пример #1
0
 def load_output(self, output_id):  # type: (int) -> OutputDTO
     output = Output.select(Room) \
                    .join_from(Output, Room, join_type=JOIN.LEFT_OUTER) \
                    .where(Output.number == output_id) \
                    .get()  # type: Output  # TODO: Load dict
     output_dto = self._master_controller.load_output(output_id=output_id)
     output_dto.room = output.room.number if output.room is not None else None
     return output_dto
Пример #2
0
 def load_outputs(self):  # type: () -> List[OutputDTO]
     output_dtos = []
     for output in list(
             Output.select(Output, Room).join_from(
                 Output, Room,
                 join_type=JOIN.LEFT_OUTER)):  # TODO: Load dicts
         output_dto = self._master_controller.load_output(
             output_id=output.number)
         output_dto.room = output.room.number if output.room is not None else None
         output_dtos.append(output_dto)
     self._cache.update_outputs(output_dtos)
     return output_dtos
Пример #3
0
    def test_orm_sync(self):
        events = []

        def handle_event(gateway_event):
            events.append(gateway_event)

        self.pubsub.subscribe_gateway_events(PubSub.GatewayTopics.CONFIG,
                                             handle_event)

        output_dto = OutputDTO(id=42)
        with mock.patch.object(self.master_controller,
                               'load_outputs',
                               return_value=[output_dto]):
            self.controller.run_sync_orm()
            self.pubsub._publish_all_events()
            assert Output.select().where(
                Output.number == output_dto.id).count() == 1
            assert GatewayEvent(GatewayEvent.Types.CONFIG_CHANGE,
                                {'type': 'output'}) in events
            assert len(events) == 1
Пример #4
0
    def set_all_lights(
        self,
        action,
        floor_id=None
    ):  # type: (Literal['ON', 'OFF', 'TOGGLE'], Optional[int]) -> None
        # TODO: Also include other sources (e.g. plugins) once implemented
        if floor_id is None:
            self._master_controller.set_all_lights(action=action)
            return

        # TODO: Filter on output type "light" once available
        query = Output.select(Output.number) \
                      .join_from(Output, Room, join_type=JOIN.INNER) \
                      .join_from(Room, Floor, join_type=JOIN.INNER) \
                      .where(Floor.number == floor_id)
        output_ids = [output['number'] for output in query.dicts()]

        # It is unknown whether `floor` is known to the Master implementation. So pass both the floor_id
        # and the list of Output ids to the MasterController
        self._master_controller.set_all_lights(action=action,
                                               floor_id=floor_id,
                                               output_ids=output_ids)