Fix LCN cover behavior when using output ports (#37034)
* Fixed LCN cover behavior when connected to output ports * Cover is assumed to be in an open state unless it is fully closed.
This commit is contained in:
parent
02adcc532f
commit
4a65bed0eb
1 changed files with 42 additions and 22 deletions
|
@ -49,9 +49,10 @@ class LcnOutputsCover(LcnDevice, CoverEntity):
|
|||
]
|
||||
else:
|
||||
self.reverse_time = None
|
||||
self._closed = None
|
||||
self.state_up = False
|
||||
self.state_down = False
|
||||
|
||||
self._is_closed = False
|
||||
self._is_closing = False
|
||||
self._is_opening = False
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Run when entity about to be added to hass."""
|
||||
|
@ -66,26 +67,44 @@ class LcnOutputsCover(LcnDevice, CoverEntity):
|
|||
@property
|
||||
def is_closed(self):
|
||||
"""Return if the cover is closed."""
|
||||
return self._closed
|
||||
return self._is_closed
|
||||
|
||||
@property
|
||||
def is_opening(self):
|
||||
"""Return if the cover is opening or not."""
|
||||
return self._is_opening
|
||||
|
||||
@property
|
||||
def is_closing(self):
|
||||
"""Return if the cover is closing or not."""
|
||||
return self._is_closing
|
||||
|
||||
@property
|
||||
def assumed_state(self):
|
||||
"""Return True if unable to access real state of the entity."""
|
||||
return True
|
||||
|
||||
async def async_close_cover(self, **kwargs):
|
||||
"""Close the cover."""
|
||||
self._closed = True
|
||||
|
||||
self._is_opening = False
|
||||
self._is_closing = True
|
||||
state = pypck.lcn_defs.MotorStateModifier.DOWN
|
||||
self.address_connection.control_motors_outputs(state)
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_open_cover(self, **kwargs):
|
||||
"""Open the cover."""
|
||||
self._closed = False
|
||||
self._is_closed = False
|
||||
self._is_opening = True
|
||||
self._is_closing = False
|
||||
state = pypck.lcn_defs.MotorStateModifier.UP
|
||||
self.address_connection.control_motors_outputs(state, self.reverse_time)
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_stop_cover(self, **kwargs):
|
||||
"""Stop the cover."""
|
||||
self._closed = None
|
||||
self._is_closing = False
|
||||
self._is_opening = False
|
||||
state = pypck.lcn_defs.MotorStateModifier.STOP
|
||||
self.address_connection.control_motors_outputs(state, self.reverse_time)
|
||||
self.async_write_ha_state()
|
||||
|
@ -98,15 +117,19 @@ class LcnOutputsCover(LcnDevice, CoverEntity):
|
|||
):
|
||||
return
|
||||
|
||||
if input_obj.get_output_id() == self.output_ids[0]:
|
||||
self.state_up = input_obj.get_percent() > 0
|
||||
else: # self.output_ids[1]
|
||||
self.state_down = input_obj.get_percent() > 0
|
||||
|
||||
if self.state_up and not self.state_down:
|
||||
self._closed = False # Cover open
|
||||
elif self.state_down and not self.state_up:
|
||||
self._closed = True # Cover closed
|
||||
if input_obj.get_percent() > 0: # motor is on
|
||||
if input_obj.get_output_id() == self.output_ids[0]:
|
||||
self._is_opening = True
|
||||
self._is_closing = False
|
||||
else: # self.output_ids[1]
|
||||
self._is_opening = False
|
||||
self._is_closing = True
|
||||
self._is_closed = self._is_closing
|
||||
else: # motor is off
|
||||
# cover is assumed to be closed if we were in closing state before
|
||||
self._is_closed = self._is_closing
|
||||
self._is_closing = False
|
||||
self._is_opening = False
|
||||
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
@ -153,7 +176,6 @@ class LcnRelayCover(LcnDevice, CoverEntity):
|
|||
|
||||
async def async_close_cover(self, **kwargs):
|
||||
"""Close the cover."""
|
||||
self._is_closed = True
|
||||
self._is_opening = False
|
||||
self._is_closing = True
|
||||
states = [pypck.lcn_defs.MotorStateModifier.NOCHANGE] * 4
|
||||
|
@ -173,8 +195,6 @@ class LcnRelayCover(LcnDevice, CoverEntity):
|
|||
|
||||
async def async_stop_cover(self, **kwargs):
|
||||
"""Stop the cover."""
|
||||
if self._is_opening or self._is_closing:
|
||||
self._is_closed = self._is_closing
|
||||
self._is_closing = False
|
||||
self._is_opening = False
|
||||
states = [pypck.lcn_defs.MotorStateModifier.NOCHANGE] * 4
|
||||
|
@ -191,9 +211,9 @@ class LcnRelayCover(LcnDevice, CoverEntity):
|
|||
if states[self.motor_port_onoff]: # motor is on
|
||||
self._is_opening = not states[self.motor_port_updown] # set direction
|
||||
self._is_closing = states[self.motor_port_updown] # set direction
|
||||
self._is_closed = self._is_closing
|
||||
else:
|
||||
else: # motor is off
|
||||
self._is_opening = False
|
||||
self._is_closing = False
|
||||
self._is_closed = states[self.motor_port_updown]
|
||||
|
||||
self.async_write_ha_state()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue