mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
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:
parent
0969e50553
commit
9d016dd434
@ -1492,6 +1492,7 @@ omit =
|
|||||||
homeassistant/components/zwave_me/button.py
|
homeassistant/components/zwave_me/button.py
|
||||||
homeassistant/components/zwave_me/cover.py
|
homeassistant/components/zwave_me/cover.py
|
||||||
homeassistant/components/zwave_me/climate.py
|
homeassistant/components/zwave_me/climate.py
|
||||||
|
homeassistant/components/zwave_me/fan.py
|
||||||
homeassistant/components/zwave_me/helpers.py
|
homeassistant/components/zwave_me/helpers.py
|
||||||
homeassistant/components/zwave_me/light.py
|
homeassistant/components/zwave_me/light.py
|
||||||
homeassistant/components/zwave_me/lock.py
|
homeassistant/components/zwave_me/lock.py
|
||||||
|
@ -13,6 +13,7 @@ class ZWaveMePlatform(StrEnum):
|
|||||||
BUTTON = "toggleButton"
|
BUTTON = "toggleButton"
|
||||||
CLIMATE = "thermostat"
|
CLIMATE = "thermostat"
|
||||||
COVER = "motor"
|
COVER = "motor"
|
||||||
|
FAN = "fan"
|
||||||
LOCK = "doorlock"
|
LOCK = "doorlock"
|
||||||
NUMBER = "switchMultilevel"
|
NUMBER = "switchMultilevel"
|
||||||
SWITCH = "switchBinary"
|
SWITCH = "switchBinary"
|
||||||
@ -27,6 +28,7 @@ PLATFORMS = [
|
|||||||
Platform.BUTTON,
|
Platform.BUTTON,
|
||||||
Platform.CLIMATE,
|
Platform.CLIMATE,
|
||||||
Platform.COVER,
|
Platform.COVER,
|
||||||
|
Platform.FAN,
|
||||||
Platform.LIGHT,
|
Platform.LIGHT,
|
||||||
Platform.LOCK,
|
Platform.LOCK,
|
||||||
Platform.NUMBER,
|
Platform.NUMBER,
|
||||||
|
72
homeassistant/components/zwave_me/fan.py
Normal file
72
homeassistant/components/zwave_me/fan.py
Normal 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)
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Z-Wave.Me",
|
"name": "Z-Wave.Me",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/zwave_me",
|
"documentation": "https://www.home-assistant.io/integrations/zwave_me",
|
||||||
"iot_class": "local_push",
|
"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"],
|
"after_dependencies": ["zeroconf"],
|
||||||
"zeroconf": [{ "type": "_hap._tcp.local.", "name": "*z.wave-me*" }],
|
"zeroconf": [{ "type": "_hap._tcp.local.", "name": "*z.wave-me*" }],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
|
@ -2506,4 +2506,4 @@ zm-py==0.5.2
|
|||||||
zwave-js-server-python==0.35.2
|
zwave-js-server-python==0.35.2
|
||||||
|
|
||||||
# homeassistant.components.zwave_me
|
# homeassistant.components.zwave_me
|
||||||
zwave_me_ws==0.2.3
|
zwave_me_ws==0.2.4
|
||||||
|
@ -1628,4 +1628,4 @@ zigpy==0.44.2
|
|||||||
zwave-js-server-python==0.35.2
|
zwave-js-server-python==0.35.2
|
||||||
|
|
||||||
# homeassistant.components.zwave_me
|
# homeassistant.components.zwave_me
|
||||||
zwave_me_ws==0.2.3
|
zwave_me_ws==0.2.4
|
||||||
|
Loading…
x
Reference in New Issue
Block a user