Update WiLight Cover Fan Light (#46366)

This commit is contained in:
Leonardo Figueiro 2021-02-11 04:25:42 -03:00 committed by GitHub
parent 56adc9dadb
commit 3ffa42e56a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 9 deletions

View file

@ -1,8 +1,6 @@
"""The WiLight integration.""" """The WiLight integration."""
import asyncio import asyncio
from pywilight.const import DOMAIN
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
@ -10,6 +8,8 @@ from homeassistant.helpers.entity import Entity
from .parent_device import WiLightParent from .parent_device import WiLightParent
DOMAIN = "wilight"
# List the platforms that you want to support. # List the platforms that you want to support.
PLATFORMS = ["cover", "fan", "light"] PLATFORMS = ["cover", "fan", "light"]

View file

@ -7,7 +7,7 @@ from homeassistant.components import ssdp
from homeassistant.config_entries import CONN_CLASS_LOCAL_PUSH, ConfigFlow from homeassistant.config_entries import CONN_CLASS_LOCAL_PUSH, ConfigFlow
from homeassistant.const import CONF_HOST from homeassistant.const import CONF_HOST
DOMAIN = "wilight" from . import DOMAIN # pylint: disable=unused-import
CONF_SERIAL_NUMBER = "serial_number" CONF_SERIAL_NUMBER = "serial_number"
CONF_MODEL_NAME = "model_name" CONF_MODEL_NAME = "model_name"

View file

@ -2,7 +2,6 @@
from pywilight.const import ( from pywilight.const import (
COVER_V1, COVER_V1,
DOMAIN,
ITEM_COVER, ITEM_COVER,
WL_CLOSE, WL_CLOSE,
WL_CLOSING, WL_CLOSING,
@ -16,7 +15,7 @@ from homeassistant.components.cover import ATTR_POSITION, CoverEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from . import WiLightDevice from . import DOMAIN, WiLightDevice
async def async_setup_entry( async def async_setup_entry(

View file

@ -1,7 +1,6 @@
"""Support for WiLight Fan.""" """Support for WiLight Fan."""
from pywilight.const import ( from pywilight.const import (
DOMAIN,
FAN_V1, FAN_V1,
ITEM_FAN, ITEM_FAN,
WL_DIRECTION_FORWARD, WL_DIRECTION_FORWARD,
@ -25,7 +24,7 @@ from homeassistant.util.percentage import (
percentage_to_ordered_list_item, percentage_to_ordered_list_item,
) )
from . import WiLightDevice from . import DOMAIN, WiLightDevice
ORDERED_NAMED_FAN_SPEEDS = [WL_SPEED_LOW, WL_SPEED_MEDIUM, WL_SPEED_HIGH] ORDERED_NAMED_FAN_SPEEDS = [WL_SPEED_LOW, WL_SPEED_MEDIUM, WL_SPEED_HIGH]
@ -80,6 +79,9 @@ class WiLightFan(WiLightDevice, FanEntity):
@property @property
def percentage(self) -> str: def percentage(self) -> str:
"""Return the current speed percentage.""" """Return the current speed percentage."""
if "direction" in self._status:
if self._status["direction"] == WL_DIRECTION_OFF:
return 0
wl_speed = self._status.get("speed") wl_speed = self._status.get("speed")
if wl_speed is None: if wl_speed is None:
return None return None
@ -111,6 +113,9 @@ class WiLightFan(WiLightDevice, FanEntity):
if percentage == 0: if percentage == 0:
await self._client.set_fan_direction(self._index, WL_DIRECTION_OFF) await self._client.set_fan_direction(self._index, WL_DIRECTION_OFF)
return return
if "direction" in self._status:
if self._status["direction"] == WL_DIRECTION_OFF:
await self._client.set_fan_direction(self._index, self._direction)
wl_speed = percentage_to_ordered_list_item(ORDERED_NAMED_FAN_SPEEDS, percentage) wl_speed = percentage_to_ordered_list_item(ORDERED_NAMED_FAN_SPEEDS, percentage)
await self._client.set_fan_speed(self._index, wl_speed) await self._client.set_fan_speed(self._index, wl_speed)

View file

@ -1,7 +1,6 @@
"""Support for WiLight lights.""" """Support for WiLight lights."""
from pywilight.const import ( from pywilight.const import (
DOMAIN,
ITEM_LIGHT, ITEM_LIGHT,
LIGHT_COLOR, LIGHT_COLOR,
LIGHT_DIMMER, LIGHT_DIMMER,
@ -19,7 +18,7 @@ from homeassistant.components.light import (
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from . import WiLightDevice from . import DOMAIN, WiLightDevice
def entities_from_discovered_wilight(hass, api_device): def entities_from_discovered_wilight(hass, api_device):