forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Cover to Z-Wave.Me integration (home-assistant#68233)
* 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
1 parent
994ea04
commit 972afc5
Showing
6 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters