2019-02-14 04:35:12 +00:00
|
|
|
"""Support for MySensors covers."""
|
2016-09-30 23:36:04 +00:00
|
|
|
from homeassistant.components import mysensors
|
2020-04-25 16:07:15 +00:00
|
|
|
from homeassistant.components.cover import ATTR_POSITION, DOMAIN, CoverEntity
|
2018-01-21 06:35:38 +00:00
|
|
|
from homeassistant.const import STATE_OFF, STATE_ON
|
2016-09-30 23:36:04 +00:00
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2018-04-01 15:36:26 +00:00
|
|
|
"""Set up the mysensors platform for covers."""
|
2017-08-25 15:58:05 +00:00
|
|
|
mysensors.setup_mysensors_platform(
|
2019-07-31 19:25:30 +00:00
|
|
|
hass,
|
|
|
|
DOMAIN,
|
|
|
|
discovery_info,
|
|
|
|
MySensorsCover,
|
|
|
|
async_add_entities=async_add_entities,
|
|
|
|
)
|
2016-09-30 23:36:04 +00:00
|
|
|
|
|
|
|
|
2020-04-25 16:07:15 +00:00
|
|
|
class MySensorsCover(mysensors.device.MySensorsEntity, CoverEntity):
|
2016-09-30 23:36:04 +00:00
|
|
|
"""Representation of the value of a MySensors Cover child node."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def assumed_state(self):
|
|
|
|
"""Return True if unable to access real state of entity."""
|
|
|
|
return self.gateway.optimistic
|
|
|
|
|
|
|
|
@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
|
2017-07-06 06:30:01 +00:00
|
|
|
return self._values.get(set_req.V_LIGHT) == STATE_OFF
|
2016-09-30 23:36:04 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def current_cover_position(self):
|
|
|
|
"""Return current position of cover.
|
|
|
|
|
|
|
|
None is unknown, 0 is closed, 100 is fully open.
|
|
|
|
"""
|
|
|
|
set_req = self.gateway.const.SetReq
|
|
|
|
return self._values.get(set_req.V_DIMMER)
|
|
|
|
|
2018-05-11 07:39:18 +00:00
|
|
|
async def async_open_cover(self, **kwargs):
|
2016-09-30 23:36:04 +00:00
|
|
|
"""Move the cover up."""
|
|
|
|
set_req = self.gateway.const.SetReq
|
2019-09-25 21:20:02 +00:00
|
|
|
self.gateway.set_child_value(
|
|
|
|
self.node_id, self.child_id, set_req.V_UP, 1, ack=1
|
|
|
|
)
|
2016-09-30 23:36:04 +00:00
|
|
|
if self.gateway.optimistic:
|
|
|
|
# Optimistically assume that cover has changed state.
|
|
|
|
if set_req.V_DIMMER in self._values:
|
|
|
|
self._values[set_req.V_DIMMER] = 100
|
|
|
|
else:
|
|
|
|
self._values[set_req.V_LIGHT] = STATE_ON
|
2020-04-01 21:19:51 +00:00
|
|
|
self.async_write_ha_state()
|
2016-09-30 23:36:04 +00:00
|
|
|
|
2018-05-11 07:39:18 +00:00
|
|
|
async def async_close_cover(self, **kwargs):
|
2016-09-30 23:36:04 +00:00
|
|
|
"""Move the cover down."""
|
|
|
|
set_req = self.gateway.const.SetReq
|
2019-09-25 21:20:02 +00:00
|
|
|
self.gateway.set_child_value(
|
|
|
|
self.node_id, self.child_id, set_req.V_DOWN, 1, ack=1
|
|
|
|
)
|
2016-09-30 23:36:04 +00:00
|
|
|
if self.gateway.optimistic:
|
|
|
|
# Optimistically assume that cover has changed state.
|
|
|
|
if set_req.V_DIMMER in self._values:
|
|
|
|
self._values[set_req.V_DIMMER] = 0
|
|
|
|
else:
|
|
|
|
self._values[set_req.V_LIGHT] = STATE_OFF
|
2020-04-01 21:19:51 +00:00
|
|
|
self.async_write_ha_state()
|
2016-09-30 23:36:04 +00:00
|
|
|
|
2018-05-11 07:39:18 +00:00
|
|
|
async def async_set_cover_position(self, **kwargs):
|
2016-09-30 23:36:04 +00:00
|
|
|
"""Move the cover to a specific position."""
|
|
|
|
position = kwargs.get(ATTR_POSITION)
|
|
|
|
set_req = self.gateway.const.SetReq
|
|
|
|
self.gateway.set_child_value(
|
2019-09-25 21:20:02 +00:00
|
|
|
self.node_id, self.child_id, set_req.V_DIMMER, position, ack=1
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2016-09-30 23:36:04 +00:00
|
|
|
if self.gateway.optimistic:
|
|
|
|
# Optimistically assume that cover has changed state.
|
|
|
|
self._values[set_req.V_DIMMER] = position
|
2020-04-01 21:19:51 +00:00
|
|
|
self.async_write_ha_state()
|
2016-09-30 23:36:04 +00:00
|
|
|
|
2018-05-11 07:39:18 +00:00
|
|
|
async def async_stop_cover(self, **kwargs):
|
2016-09-30 23:36:04 +00:00
|
|
|
"""Stop the device."""
|
|
|
|
set_req = self.gateway.const.SetReq
|
2019-09-25 21:20:02 +00:00
|
|
|
self.gateway.set_child_value(
|
|
|
|
self.node_id, self.child_id, set_req.V_STOP, 1, ack=1
|
|
|
|
)
|