mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Use the action field enums in switchbee (#194676)
This commit is contained in:
@@ -7,10 +7,10 @@ from switchbee.const import SomfyCommand
|
||||
from switchbee.device import SwitchBeeShutter, SwitchBeeSomfy
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
ATTR_POSITION,
|
||||
CoverDeviceClass,
|
||||
CoverEntity,
|
||||
CoverEntityFeature,
|
||||
CoverServiceArgument,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
@@ -142,18 +142,20 @@ class SwitchBeeCoverEntity(SwitchBeeDeviceEntity[SwitchBeeShutter], CoverEntity)
|
||||
async def async_set_cover_position(self, **kwargs: Any) -> None:
|
||||
"""Async function to set position to cover."""
|
||||
if (
|
||||
self.current_cover_position == kwargs[ATTR_POSITION]
|
||||
self.current_cover_position == kwargs[CoverServiceArgument.POSITION]
|
||||
and "force" not in kwargs
|
||||
):
|
||||
return
|
||||
try:
|
||||
await self.coordinator.api.set_state(self._device.id, kwargs[ATTR_POSITION])
|
||||
await self.coordinator.api.set_state(
|
||||
self._device.id, kwargs[CoverServiceArgument.POSITION]
|
||||
)
|
||||
except (SwitchBeeError, SwitchBeeTokenError) as exp:
|
||||
raise HomeAssistantError(
|
||||
f"Failed to set {self.name} position to {kwargs[ATTR_POSITION]}, error:"
|
||||
f"Failed to set {self.name} position to {kwargs[CoverServiceArgument.POSITION]}, error:"
|
||||
f" {exp!s}"
|
||||
) from exp
|
||||
|
||||
self._get_coordinator_device().position = kwargs[ATTR_POSITION]
|
||||
self._get_coordinator_device().position = kwargs[CoverServiceArgument.POSITION]
|
||||
self.coordinator.async_set_updated_data(self.coordinator.data)
|
||||
self.async_write_ha_state()
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import Any, cast, override
|
||||
from switchbee.api.central_unit import SwitchBeeDeviceOfflineError, SwitchBeeError
|
||||
from switchbee.device import ApiStateCommand, DeviceType, SwitchBeeDimmer
|
||||
|
||||
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
|
||||
from homeassistant.components.light import ColorMode, LightEntity, LightServiceArgument
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
@@ -89,8 +89,10 @@ class SwitchBeeLightEntity(SwitchBeeDeviceEntity[SwitchBeeDimmer], LightEntity):
|
||||
@override
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Async function to set on to light."""
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
state: int | str = _hass_brightness_to_switchbee(kwargs[ATTR_BRIGHTNESS])
|
||||
if LightServiceArgument.BRIGHTNESS in kwargs:
|
||||
state: int | str = _hass_brightness_to_switchbee(
|
||||
kwargs[LightServiceArgument.BRIGHTNESS]
|
||||
)
|
||||
else:
|
||||
state = ApiStateCommand.ON
|
||||
if self.brightness:
|
||||
|
||||
Reference in New Issue
Block a user