Skip to content

Commit

Permalink
refactor garagedoor state request trying fix #498
Browse files Browse the repository at this point in the history
  • Loading branch information
krahabb committed Oct 15, 2024
1 parent f32bcb3 commit acc7b0f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions custom_components/meross_lan/devices/garageDoor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ..switch import MLSwitch

if typing.TYPE_CHECKING:
from ..merossclient import MerossRequestType
from ..meross_device import DigestInitReturnType, MerossDevice
from ..number import MLConfigNumberArgs

Expand Down Expand Up @@ -275,8 +276,11 @@ class MLGarage(MLCover):
MLCover.EntityFeature.OPEN | MLCover.EntityFeature.CLOSE
)

_state_request: "MerossRequestType"

__slots__ = (
"_config",
"_state_request",
"_transition_duration",
"_transition_start",
"binary_sensor_timeout",
Expand All @@ -295,6 +299,18 @@ def __init__(self, manager: "MerossDevice", channel: object):
self.ATTR_TRANSITION_DURATION: self._transition_duration
}
super().__init__(manager, channel, MLCover.DeviceClass.GARAGE)
if channel:
self._state_request = (
mn.Appliance_GarageDoor_State.name,
mc.METHOD_GET,
{
mn.Appliance_GarageDoor_State.key: [
{mn.Appliance_GarageDoor_State.key_channel: channel}
]
},
)
else:
self._state_request = mn.Appliance_GarageDoor_State.request_default
ability = manager.descriptor.ability
manager.register_parser_entity(self)
manager.register_togglex_channel(self)
Expand Down Expand Up @@ -542,9 +558,7 @@ async def _async_transition_callback(self):
self._transition_unsub = None
manager = self.manager
if manager.curr_protocol is CONF_PROTOCOL_HTTP and not manager._mqtt_active:
await manager.async_http_request(
*mn.Appliance_GarageDoor_State.request_default
)
await manager.async_http_request(*self._state_request)

async def _async_transition_end_callback(self):
"""
Expand All @@ -569,7 +583,7 @@ async def _async_transition_end_callback(self):
if was_closing != self.is_closed:
# looks like on MQTT we don't receive a PUSHed state update? (#415)
if await self.manager.async_request_ack(
*mn.Appliance_GarageDoor_State.request_default
*self._state_request
):
# the request/response parse already flushed the state
if was_closing == self.is_closed:
Expand Down

0 comments on commit acc7b0f

Please sign in to comment.