Exemplo n.º 1
0
 async def set_state(
     self,
     address: str,
     state: SetStateDTO,
     timeout=DEFAULT_TIMEOUT,
     attempts=DEFAULT_ATTEMPTS,
 ) -> PranaStateDTO:
     features = [state.speed, state.mode, state.winter_mode, state.heating]
     if all(v is None for v in features):
         raise ValueError("At least one parameter must be set. Check your arguments.")
     prana_device = await self.get_connected_prana_device(address, timeout, attempts)
     if state.speed is not None:
         await prana_device.set_speed(state.speed)
     if state.heating is not None:
         await prana_device.set_heating(state.heating)
     if state.winter_mode is not None:
         await prana_device.set_winter_mode(state.winter_mode)
     if state.mode is not None:
         if state.mode == Mode.NIGHT:
             await prana_device.set_night_mode()
         elif state.mode == Mode.NORMAL:
             await prana_device.set_normal_speed()
         elif state.mode == Mode.HIGH:
             await prana_device.set_high_speed()
     new_state = await prana_device.read_state()
     return utils.none_throws(ToDTO.prana_state(new_state))
Exemplo n.º 2
0
 async def read_state(self, force_read: bool = False) -> PranaState:
     """
     Read state from the devcie and return it as an object
     :param force_read: If set, cached state will be ignored and read command to the device will be generated
     :return:
     """
     await self.__verify_connected()
     state_bin = await self._send_command(self.Cmd.READ_STATE,
                                          expect_reply=True)
     state = self.__parse_state(state_bin)
     if state is not None:
         self.__state = state
     return utils.none_throws(state)
Exemplo n.º 3
0
 async def set_brightness(self, brightness: int):
     if brightness < 0 or brightness > 6:
         raise ValueError("brightness value must be in range 0-6")
     original_state = await self.read_state()
     original_brightness = none_throws(original_state.brightness)
     if brightness == original_brightness:
         return
     if brightness > original_brightness:
         counter = brightness - original_brightness
     else:
         counter = brightness + (self.MAX_BRIGHTNESS - original_brightness)
     while counter > 0:
         await self.brightness_up()
         counter -= 1
Exemplo n.º 4
0
 def __has_relevant_state(self) -> bool:
     return not (self.__state is None or
                 (datetime.datetime.now() - utils.none_throws(
                     self.__state.timestamp)).total_seconds() > 60)
Exemplo n.º 5
0
 async def get_state(self, address: str, timeout=DEFAULT_TIMEOUT, attempts=DEFAULT_ATTEMPTS) -> PranaStateDTO:
     prana_device = await self.get_connected_prana_device(address, timeout, attempts)
     state = await prana_device.read_state()
     return utils.none_throws(ToDTO.prana_state(state))
Exemplo n.º 6
0
 async def discover(self, timeout=4) -> List[PranaDeviceInfoDTO]:
     res = await self.__device_manager.discover(timeout)
     return [utils.none_throws(ToDTO.prana_device_info(d)) for d in res]