mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Use the action field enums in wilight (#194932)
This commit is contained in:
@@ -13,7 +13,7 @@ from pywilight.const import (
|
||||
WL_STOPPED,
|
||||
)
|
||||
|
||||
from homeassistant.components.cover import ATTR_POSITION, CoverEntity
|
||||
from homeassistant.components.cover import CoverEntity, CoverServiceArgument
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
@@ -110,7 +110,7 @@ class WiLightCover(WiLightDevice, CoverEntity):
|
||||
@override
|
||||
async def async_set_cover_position(self, **kwargs: Any) -> None:
|
||||
"""Move the cover to a specific position."""
|
||||
position = hass_to_wilight_position(kwargs[ATTR_POSITION])
|
||||
position = hass_to_wilight_position(kwargs[CoverServiceArgument.POSITION])
|
||||
await self._client.set_cover_position(self._index, position)
|
||||
|
||||
@override
|
||||
|
||||
@@ -5,12 +5,7 @@ from typing import Any, override
|
||||
from pywilight.const import ITEM_LIGHT, LIGHT_COLOR, LIGHT_DIMMER, LIGHT_ON_OFF
|
||||
from pywilight.wilight_device import PyWiLightDevice
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_HS_COLOR,
|
||||
ColorMode,
|
||||
LightEntity,
|
||||
)
|
||||
from homeassistant.components.light import ColorMode, LightEntity, LightServiceArgument
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
@@ -98,8 +93,8 @@ class WiLightLightDimmer(WiLightDevice, LightEntity):
|
||||
"""Turn the device on,set brightness if needed."""
|
||||
# Dimmer switches use a range of [0, 255] to control
|
||||
# brightness. Level 255 might mean to set it to previous value
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
brightness = kwargs[ATTR_BRIGHTNESS]
|
||||
if LightServiceArgument.BRIGHTNESS in kwargs:
|
||||
brightness = kwargs[LightServiceArgument.BRIGHTNESS]
|
||||
await self._client.set_brightness(self._index, brightness)
|
||||
else:
|
||||
await self._client.turn_on(self._index)
|
||||
@@ -164,17 +159,30 @@ class WiLightLightColor(WiLightDevice, LightEntity):
|
||||
# Brightness use a range of [0, 255] to control
|
||||
# Hue use a range of [0, 360] to control
|
||||
# Saturation use a range of [0, 100] to control
|
||||
if ATTR_BRIGHTNESS in kwargs and ATTR_HS_COLOR in kwargs:
|
||||
brightness = kwargs[ATTR_BRIGHTNESS]
|
||||
hue = hass_to_wilight_hue(kwargs[ATTR_HS_COLOR][0])
|
||||
saturation = hass_to_wilight_saturation(kwargs[ATTR_HS_COLOR][1])
|
||||
if (
|
||||
LightServiceArgument.BRIGHTNESS in kwargs
|
||||
and LightServiceArgument.HS_COLOR in kwargs
|
||||
):
|
||||
brightness = kwargs[LightServiceArgument.BRIGHTNESS]
|
||||
hue = hass_to_wilight_hue(kwargs[LightServiceArgument.HS_COLOR][0])
|
||||
saturation = hass_to_wilight_saturation(
|
||||
kwargs[LightServiceArgument.HS_COLOR][1]
|
||||
)
|
||||
await self._client.set_hsb_color(self._index, hue, saturation, brightness)
|
||||
elif ATTR_BRIGHTNESS in kwargs and ATTR_HS_COLOR not in kwargs:
|
||||
brightness = kwargs[ATTR_BRIGHTNESS]
|
||||
elif (
|
||||
LightServiceArgument.BRIGHTNESS in kwargs
|
||||
and LightServiceArgument.HS_COLOR not in kwargs
|
||||
):
|
||||
brightness = kwargs[LightServiceArgument.BRIGHTNESS]
|
||||
await self._client.set_brightness(self._index, brightness)
|
||||
elif ATTR_BRIGHTNESS not in kwargs and ATTR_HS_COLOR in kwargs:
|
||||
hue = hass_to_wilight_hue(kwargs[ATTR_HS_COLOR][0])
|
||||
saturation = hass_to_wilight_saturation(kwargs[ATTR_HS_COLOR][1])
|
||||
elif (
|
||||
LightServiceArgument.BRIGHTNESS not in kwargs
|
||||
and LightServiceArgument.HS_COLOR in kwargs
|
||||
):
|
||||
hue = hass_to_wilight_hue(kwargs[LightServiceArgument.HS_COLOR][0])
|
||||
saturation = hass_to_wilight_saturation(
|
||||
kwargs[LightServiceArgument.HS_COLOR][1]
|
||||
)
|
||||
await self._client.set_hs_color(self._index, hue, saturation)
|
||||
else:
|
||||
await self._client.turn_on(self._index)
|
||||
|
||||
Reference in New Issue
Block a user