Add Z-Wave.Me Fan support (#69768)

* Fan entity

* Fix union

* Fix union

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Fix percentage scale

Co-authored-by: Dmitry Vlasov <kerbalspacema@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Poltorak Serguei 2022-04-19 14:06:31 +03:00 committed by GitHub
parent 0969e50553
commit 9d016dd434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 3 deletions

View File

@ -1492,6 +1492,7 @@ omit =
homeassistant/components/zwave_me/button.py
homeassistant/components/zwave_me/cover.py
homeassistant/components/zwave_me/climate.py
homeassistant/components/zwave_me/fan.py
homeassistant/components/zwave_me/helpers.py
homeassistant/components/zwave_me/light.py
homeassistant/components/zwave_me/lock.py

View File

@ -13,6 +13,7 @@ class ZWaveMePlatform(StrEnum):
BUTTON = "toggleButton"
CLIMATE = "thermostat"
COVER = "motor"
FAN = "fan"
LOCK = "doorlock"
NUMBER = "switchMultilevel"
SWITCH = "switchBinary"
@ -27,6 +28,7 @@ PLATFORMS = [
Platform.BUTTON,
Platform.CLIMATE,
Platform.COVER,
Platform.FAN,
Platform.LIGHT,
Platform.LOCK,
Platform.NUMBER,

View File

@ -0,0 +1,72 @@
"""Representation of a fan."""
from __future__ import annotations
from typing import Any
from homeassistant.components.fan import FanEntity, FanEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import ZWaveMeEntity
from .const import DOMAIN, ZWaveMePlatform
DEVICE_NAME = ZWaveMePlatform.FAN
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the fan platform."""
@callback
def add_new_device(new_device):
controller = hass.data[DOMAIN][config_entry.entry_id]
fan = ZWaveMeFan(controller, new_device)
async_add_entities(
[
fan,
]
)
config_entry.async_on_unload(
async_dispatcher_connect(
hass, f"ZWAVE_ME_NEW_{DEVICE_NAME.upper()}", add_new_device
)
)
class ZWaveMeFan(ZWaveMeEntity, FanEntity):
"""Representation of a ZWaveMe Fan."""
_attr_supported_features = FanEntityFeature.SET_SPEED
@property
def percentage(self) -> int:
"""Return the current speed as a percentage."""
if self.device.level == 99: # Scale max value
return 100
return self.device.level
def set_percentage(self, percentage: int) -> None:
"""Set the speed percentage of the fan."""
self.controller.zwave_api.send_command(
self.device.id, f"exact?level={min(percentage, 99)}"
)
def turn_off(self, **kwargs: Any) -> None:
"""Turn the fan off."""
self.controller.zwave_api.send_command(self.device.id, "exact?level=0")
def turn_on(
self,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs,
) -> None:
"""Turn on the fan."""
self.set_percentage(percentage if percentage is not None else 99)

View File

@ -3,7 +3,7 @@
"name": "Z-Wave.Me",
"documentation": "https://www.home-assistant.io/integrations/zwave_me",
"iot_class": "local_push",
"requirements": ["zwave_me_ws==0.2.3", "url-normalize==1.4.1"],
"requirements": ["zwave_me_ws==0.2.4", "url-normalize==1.4.1"],
"after_dependencies": ["zeroconf"],
"zeroconf": [{ "type": "_hap._tcp.local.", "name": "*z.wave-me*" }],
"config_flow": true,

View File

@ -2506,4 +2506,4 @@ zm-py==0.5.2
zwave-js-server-python==0.35.2
# homeassistant.components.zwave_me
zwave_me_ws==0.2.3
zwave_me_ws==0.2.4

View File

@ -1628,4 +1628,4 @@ zigpy==0.44.2
zwave-js-server-python==0.35.2
# homeassistant.components.zwave_me
zwave_me_ws==0.2.3
zwave_me_ws==0.2.4