Example #1
0
    async def create_schedule(self, days: List[str], start_time: str,
                              stop_time: str):
        is_success = False

        try:
            weekdays = dict(map(lambda d: (d.value, d), Days))
            selected_days = ({weekdays[d]
                              for d in days[KEY_DAYS]} if days else set())

            async with SwitcherClient(self.ip_address, self.device_id) as api:
                state = await api.create_schedule(start_time, stop_time,
                                                  selected_days)

                if state.successful:
                    _LOGGER.debug(
                        f"Create Schedule successfully completed, Response: {state}"
                    )
                else:
                    _LOGGER.error(f"Failed to Create Schedule")

                is_success = state.successful

        except Exception as ex:
            exc_type, exc_obj, tb = sys.exc_info()
            line = tb.tb_lineno

            _LOGGER.error(
                f"Failed creating new schedule, {self.device_details}, Error: {ex}, Line: {line}"
            )

        return is_success
Example #2
0
    async def _toggle_state(self, action: bool, minutes: Optional[int] = 0):
        is_success = False
        command = Command.ON if action else Command.OFF
        command_name = "On" if action else "Off"

        try:
            async with SwitcherClient(self.ip_address, self.device_id) as api:
                state = await api.control_device(command, minutes)

                if state.successful:
                    _LOGGER.debug(
                        f"Turn {command_name} successfully completed, Response: {state}"
                    )

                    await self.async_update()

                else:
                    _LOGGER.error(
                        f"Failed to Turn {command_name}, {self.device_details}"
                    )

                is_success = state.successful

        except Exception as ex:
            exc_type, exc_obj, tb = sys.exc_info()
            line = tb.tb_lineno

            _LOGGER.error(
                f"Failed to Turn {command_name} the device, {self.device_details}, Error: {ex}, Line: {line}"
            )

        return is_success
Example #3
0
    async def set_device_name(self, new_name: str):
        is_success = False

        try:
            async with SwitcherClient(self.ip_address, self.device_id) as api:
                state = await api.set_device_name(new_name)

                if state.successful:
                    _LOGGER.debug(
                        f"Device Name Set successfully completed, Response: {state}"
                    )
                else:
                    _LOGGER.error(f"Failed to Set Device Name")

                is_success = state.successful

        except Exception as ex:
            exc_type, exc_obj, tb = sys.exc_info()
            line = tb.tb_lineno

            _LOGGER.error(
                f"Failed setting the device name, {self.device_details}, Error: {ex}, Line: {line}"
            )

        return is_success
Example #4
0
    async def set_auto_shutdown(self, time_span: time):
        is_success = False

        try:
            async with SwitcherClient(self.ip_address, self.device_id) as api:
                auto_shutdown = timedelta(hours=time_span.hour,
                                          minutes=time_span.minute)
                state = await api.set_auto_shutdown(auto_shutdown)

                if state.successful:
                    _LOGGER.debug(
                        f"Auto Shutdown Set successfully completed, Response: {state}"
                    )
                else:
                    _LOGGER.error(f"Failed to Set Auto Shutdown")

                is_success = state.successful

        except Exception as ex:
            exc_type, exc_obj, tb = sys.exc_info()
            line = tb.tb_lineno

            _LOGGER.error(
                f"Failed setting auto shutdown on device, {self.device_details}, Error: {ex}, Line: {line}"
            )

        return is_success
Example #5
0
    async def _get_state(self) -> dict:
        response = None

        try:
            async with SwitcherClient(self.ip_address, self.device_id) as api:
                state = await api.get_state()

                if state.successful:
                    response = _serialize_object(state)
                    _LOGGER.debug(
                        f"Retrieved state successfully completed, Response: {state}"
                    )

                else:
                    _LOGGER.error(f"Failed to retrieve state")

        except GeneratorExit as gex:
            exc_type, exc_obj, tb = sys.exc_info()
            line = tb.tb_lineno

            error_details = f"Generator Exit Error: {gex.args}, Line: {line}"

            _LOGGER.error(
                f"Failed to get the device state, {self.device_details}, {error_details}"
            )

        except Exception as ex:
            exc_type, exc_obj, tb = sys.exc_info()
            line = tb.tb_lineno

            _LOGGER.error(
                f"Failed to get the device state, {self.device_details}, Error: {ex}, Line: {line}"
            )

        return response
Example #6
0
    async def delete_schedule(self, schedule_id: str):
        is_success = False

        try:
            async with SwitcherClient(self.ip_address, self.device_id) as api:
                state = await api.delete_schedule(schedule_id)

                if state.successful:
                    _LOGGER.debug(
                        f"Delete Schedule successfully completed, Response: {state}"
                    )
                else:
                    _LOGGER.error(f"Failed to Delete Schedule")

                is_success = state.successful

        except Exception as ex:
            exc_type, exc_obj, tb = sys.exc_info()
            line = tb.tb_lineno

            _LOGGER.error(
                f"Failed deleting schedule, {self.device_details}, Error: {ex}, Line: {line}"
            )

        return is_success