mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add OPENING & CLOSING state to MySensors cover (#47285)
* Added OPENING & CLOSING State Support Added support for OPENING and CLOSING states using a combination of the required V_ variables. Simplified the determination of the cover's state by use of a new enumeration and single method allowing the state to be used by all three HomeAssistant query methods. * Fixes for HomeAssistant Style Corrections to style to allow flake8, isort, and black to pass. * Peer Review Changes Added @unique to the main enumeration. Removed unnecessary parens from door state logic. Reordered CLOSING and CLOSED in the enumeration.
This commit is contained in:
parent
c7718f2b3b
commit
4cade4b736
@ -1,4 +1,5 @@
|
||||
"""Support for MySensors covers."""
|
||||
from enum import Enum, unique
|
||||
import logging
|
||||
from typing import Callable
|
||||
|
||||
@ -14,6 +15,16 @@ from homeassistant.helpers.typing import HomeAssistantType
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@unique
|
||||
class CoverState(Enum):
|
||||
"""An enumeration of the standard cover states."""
|
||||
|
||||
OPEN = 0
|
||||
OPENING = 1
|
||||
CLOSING = 2
|
||||
CLOSED = 3
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities: Callable
|
||||
):
|
||||
@ -43,13 +54,44 @@ async def async_setup_entry(
|
||||
class MySensorsCover(mysensors.device.MySensorsEntity, CoverEntity):
|
||||
"""Representation of the value of a MySensors Cover child node."""
|
||||
|
||||
def get_cover_state(self):
|
||||
"""Return a CoverState enum representing the state of the cover."""
|
||||
set_req = self.gateway.const.SetReq
|
||||
v_up = self._values.get(set_req.V_UP) == STATE_ON
|
||||
v_down = self._values.get(set_req.V_DOWN) == STATE_ON
|
||||
v_stop = self._values.get(set_req.V_STOP) == STATE_ON
|
||||
|
||||
# If a V_DIMMER or V_PERCENTAGE is available, that is the amount
|
||||
# the cover is open. Otherwise, use 0 or 100 based on the V_LIGHT
|
||||
# or V_STATUS.
|
||||
amount = 100
|
||||
if set_req.V_DIMMER in self._values:
|
||||
amount = self._values.get(set_req.V_DIMMER)
|
||||
else:
|
||||
amount = 100 if self._values.get(set_req.V_LIGHT) == STATE_ON else 0
|
||||
|
||||
if v_up and not v_down and not v_stop:
|
||||
return CoverState.OPENING
|
||||
if not v_up and v_down and not v_stop:
|
||||
return CoverState.CLOSING
|
||||
if not v_up and not v_down and v_stop and amount == 0:
|
||||
return CoverState.CLOSED
|
||||
return CoverState.OPEN
|
||||
|
||||
@property
|
||||
def is_closed(self):
|
||||
"""Return True if cover is closed."""
|
||||
set_req = self.gateway.const.SetReq
|
||||
if set_req.V_DIMMER in self._values:
|
||||
return self._values.get(set_req.V_DIMMER) == 0
|
||||
return self._values.get(set_req.V_LIGHT) == STATE_OFF
|
||||
"""Return True if the cover is closed."""
|
||||
return self.get_cover_state() == CoverState.CLOSED
|
||||
|
||||
@property
|
||||
def is_closing(self):
|
||||
"""Return True if the cover is closing."""
|
||||
return self.get_cover_state() == CoverState.CLOSING
|
||||
|
||||
@property
|
||||
def is_opening(self):
|
||||
"""Return True if the cover is opening."""
|
||||
return self.get_cover_state() == CoverState.OPENING
|
||||
|
||||
@property
|
||||
def current_cover_position(self):
|
||||
|
@ -162,6 +162,9 @@ class MySensorsDevice:
|
||||
set_req.V_LIGHT,
|
||||
set_req.V_LOCK_STATUS,
|
||||
set_req.V_TRIPPED,
|
||||
set_req.V_UP,
|
||||
set_req.V_DOWN,
|
||||
set_req.V_STOP,
|
||||
):
|
||||
self._values[value_type] = STATE_ON if int(value) == 1 else STATE_OFF
|
||||
elif value_type == set_req.V_DIMMER:
|
||||
|
Loading…
x
Reference in New Issue
Block a user