Skip to content

Commit

Permalink
Add Cover to Z-Wave.Me integration (home-assistant#68233)
Browse files Browse the repository at this point in the history
* Cover integration

* isort fix

* Update homeassistant/components/zwave_me/cover.py

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

* Update cover.py

* Update cover.py

* Apply suggestions from code review

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

* coveragerc for cover

* Fix position range

* Clean up

Co-authored-by: Dmitry Vlasov <kerbalspacema@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
  • Loading branch information
3 people authored Mar 20, 2022
1 parent 994ea04 commit 972afc5
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 3 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,7 @@ omit =
homeassistant/components/zwave_me/__init__.py
homeassistant/components/zwave_me/binary_sensor.py
homeassistant/components/zwave_me/button.py
homeassistant/components/zwave_me/cover.py
homeassistant/components/zwave_me/climate.py
homeassistant/components/zwave_me/helpers.py
homeassistant/components/zwave_me/light.py
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/zwave_me/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ZWaveMePlatform(StrEnum):
BINARY_SENSOR = "sensorBinary"
BUTTON = "toggleButton"
CLIMATE = "thermostat"
COVER = "motor"
LOCK = "doorlock"
NUMBER = "switchMultilevel"
SWITCH = "switchBinary"
Expand All @@ -25,6 +26,7 @@ class ZWaveMePlatform(StrEnum):
Platform.BINARY_SENSOR,
Platform.BUTTON,
Platform.CLIMATE,
Platform.COVER,
Platform.LIGHT,
Platform.LOCK,
Platform.NUMBER,
Expand Down
72 changes: 72 additions & 0 deletions homeassistant/components/zwave_me/cover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Representation of a cover."""
from __future__ import annotations

from typing import Any

from homeassistant.components.cover import (
ATTR_POSITION,
SUPPORT_CLOSE,
SUPPORT_OPEN,
SUPPORT_SET_POSITION,
CoverEntity,
)
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect

from . import ZWaveMeEntity
from .const import DOMAIN, ZWaveMePlatform

DEVICE_NAME = ZWaveMePlatform.COVER


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the cover platform."""

@callback
def add_new_device(new_device):
controller = hass.data[DOMAIN][config_entry.entry_id]
cover = ZWaveMeCover(controller, new_device)

async_add_entities(
[
cover,
]
)

config_entry.async_on_unload(
async_dispatcher_connect(
hass, f"ZWAVE_ME_NEW_{DEVICE_NAME.upper()}", add_new_device
)
)


class ZWaveMeCover(ZWaveMeEntity, CoverEntity):
"""Representation of a ZWaveMe Multilevel Cover."""

def close_cover(self, **kwargs):
"""Close cover."""
self.controller.zwave_api.send_command(self.device.id, "exact?level=0")

def open_cover(self, **kwargs):
"""Open cover."""
self.controller.zwave_api.send_command(self.device.id, "exact?level=99")

def set_cover_position(self, **kwargs: Any) -> None:
"""Update the current value."""
value = kwargs[ATTR_POSITION]
self.controller.zwave_api.send_command(
self.device.id, f"exact?level={str(min(value, 99))}"
)

@property
def current_cover_position(self) -> int | None:
"""Return current position of cover.
None is unknown, 0 is closed, 100 is fully open.
"""
return self.device.level

@property
def supported_features(self) -> int:
"""Return the supported features."""
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION
2 changes: 1 addition & 1 deletion homeassistant/components/zwave_me/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"documentation": "https://www.home-assistant.io/integrations/zwave_me",
"iot_class": "local_push",
"requirements": [
"zwave_me_ws==0.2.2",
"zwave_me_ws==0.2.3",
"url-normalize==1.4.1"
],
"after_dependencies": ["zeroconf"],
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2497,4 +2497,4 @@ zm-py==0.5.2
zwave-js-server-python==0.35.2

# homeassistant.components.zwave_me
zwave_me_ws==0.2.2
zwave_me_ws==0.2.3
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1599,4 +1599,4 @@ zigpy==0.43.0
zwave-js-server-python==0.35.2

# homeassistant.components.zwave_me
zwave_me_ws==0.2.2
zwave_me_ws==0.2.3

0 comments on commit 972afc5

Please sign in to comment.