Introduced SET_POSITION feature for covers
This commit is contained in:
@@ -25,6 +25,7 @@ from homeassistant.components.cover import (
|
|||||||
SUPPORT_CLOSE,
|
SUPPORT_CLOSE,
|
||||||
SUPPORT_OPEN,
|
SUPPORT_OPEN,
|
||||||
SUPPORT_STOP,
|
SUPPORT_STOP,
|
||||||
|
SUPPORT_SET_POSITION,
|
||||||
)
|
)
|
||||||
|
|
||||||
"""from . import DATA_TUYA, TuyaDevice"""
|
"""from . import DATA_TUYA, TuyaDevice"""
|
||||||
@@ -147,6 +148,7 @@ class TuyaDevice(CoverEntity):
|
|||||||
self._switch_id = switchid
|
self._switch_id = switchid
|
||||||
self._status = self._device.status()
|
self._status = self._device.status()
|
||||||
self._state = self._status['dps'][self._switch_id]
|
self._state = self._status['dps'][self._switch_id]
|
||||||
|
self._position = 50
|
||||||
print('Initialized tuya cover [{}] with switch status [{}] and state [{}]'.format(self._name, self._status, self._state))
|
print('Initialized tuya cover [{}] with switch status [{}] and state [{}]'.format(self._name, self._status, self._state))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -157,7 +159,7 @@ class TuyaDevice(CoverEntity):
|
|||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
supported_features = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP
|
supported_features = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION
|
||||||
return supported_features
|
return supported_features
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -165,6 +167,14 @@ class TuyaDevice(CoverEntity):
|
|||||||
"""Return the icon."""
|
"""Return the icon."""
|
||||||
return self._icon
|
return self._icon
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_cover_position(self):
|
||||||
|
#self.update()
|
||||||
|
#state = self._state
|
||||||
|
# _LOGGER.info("curr_pos() : %i", self._position)
|
||||||
|
#print('curr_pos() : state [{}]'.format(state))
|
||||||
|
return self._position
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_opening(self):
|
def is_opening(self):
|
||||||
#self.update()
|
#self.update()
|
||||||
@@ -195,6 +205,28 @@ class TuyaDevice(CoverEntity):
|
|||||||
return True
|
return True
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def set_cover_position(self, **kwargs):
|
||||||
|
"""Move the cover to a specific position."""
|
||||||
|
|
||||||
|
newpos = float(kwargs["position"])
|
||||||
|
# _LOGGER.info("Set new pos: %f", newpos)
|
||||||
|
|
||||||
|
currpos = self.current_cover_position
|
||||||
|
posdiff = abs(newpos - currpos)
|
||||||
|
# 25 sec corrisponde alla chiusura/apertura completa
|
||||||
|
mydelay = posdiff / 2.0
|
||||||
|
if newpos > currpos:
|
||||||
|
# _LOGGER.info("Opening to %f: delay %f", newpos, mydelay )
|
||||||
|
self.open_cover()
|
||||||
|
else:
|
||||||
|
# _LOGGER.info("Closing to %f: delay %f", newpos, mydelay )
|
||||||
|
self.close_cover()
|
||||||
|
sleep( mydelay )
|
||||||
|
self.stop_cover()
|
||||||
|
self._position = 50 # newpos
|
||||||
|
# self._state = 'on'
|
||||||
|
# self._device._device.open_cover()
|
||||||
|
|
||||||
def open_cover(self, **kwargs):
|
def open_cover(self, **kwargs):
|
||||||
"""Open the cover."""
|
"""Open the cover."""
|
||||||
self._device.set_status('on', self._switch_id)
|
self._device.set_status('on', self._switch_id)
|
||||||
|
Reference in New Issue
Block a user