예제 #1
0
    async def async_select_option(self, option: str) -> None:
        """Change the Select Entity Option."""
        if option not in self.options:
            raise HomeAssistantError(
                f"Cannot set the value to {option}; Allowed values are: {self.options}"
            )

        if isinstance(self.device, Light):
            if self.entity_description.key == _KEY_LIGHT_MOTION:
                lightmode, timing = LIGHT_MODE_TO_SETTINGS[option]
                _LOGGER.debug("Changing Light Mode to %s", option)
                await self.device.set_light_settings(
                    LightModeType(lightmode),
                    enable_at=None
                    if timing is None else LightModeEnableType(timing),
                )
                return

            unifi_value = self._hass_to_unifi_options[option]
            if self.entity_description.key == _KEY_PAIRED_CAMERA:
                if unifi_value == TYPE_EMPTY_VALUE:
                    unifi_value = None
                camera = self.data.api.bootstrap.cameras.get(unifi_value)
                await self.device.set_paired_camera(camera)
                _LOGGER.debug("Changed Paired Camera to to: %s", option)
                return

        unifi_value = self._hass_to_unifi_options[option]
        if isinstance(self.device, Camera):
            if self.entity_description.key == _KEY_DOORBELL_TEXT:
                if unifi_value.startswith(
                        DoorbellMessageType.CUSTOM_MESSAGE.value):
                    await self.device.set_lcd_text(
                        DoorbellMessageType.CUSTOM_MESSAGE, text=option)
                elif unifi_value == TYPE_EMPTY_VALUE:
                    await self.device.set_lcd_text(None)
                else:
                    await self.device.set_lcd_text(
                        DoorbellMessageType(unifi_value))

                _LOGGER.debug("Changed Doorbell LCD Text to: %s", option)
                return

        if self.entity_description.ufp_enum_type is not None:
            unifi_value = self.entity_description.ufp_enum_type(unifi_value)
        elif self.entity_description.key == _KEY_VIEWER:
            unifi_value = self.data.api.bootstrap.liveviews[unifi_value]

        _LOGGER.debug("%s set to: %s", self.entity_description.key, option)
        assert self.entity_description.ufp_set_function
        coro = getattr(self.device, self.entity_description.ufp_set_function)
        await coro(unifi_value)
예제 #2
0
    async def async_light_settings(
        self,
        mode: str,
        enable_at: str | None = None,
        duration: int | None = None,
        sensitivity: int | None = None,
    ) -> None:
        """Adjust Light Settings."""

        turn_off_duration: timedelta | None = None
        enable_at_mode: LightModeEnableType | None = None
        if enable_at is not None:
            enable_at_mode = LightModeEnableType(enable_at)
        if duration is not None:
            turn_off_duration = timedelta(seconds=duration)

        await self.device.set_light_settings(
            LightModeType(mode),
            enable_at=enable_at_mode,
            duration=turn_off_duration,
            sensitivity=sensitivity,
        )
예제 #3
0
파일: select.py 프로젝트: jcgoette/core
async def _set_light_mode(obj: Light, mode: str) -> None:
    lightmode, timing = LIGHT_MODE_TO_SETTINGS[mode]
    await obj.set_light_settings(
        LightModeType(lightmode),
        enable_at=None if timing is None else LightModeEnableType(timing),
    )