@@ -115,6 +115,25 @@ async def turnoff(self, wait_for_state: bool = False) -> Union[asyncio.Task, boo
115115 async def turnon (self , wait_for_state : bool = False ) -> Union [asyncio .Task , bool ]:
116116 raise NotImplementedError
117117
118+ async def update_device (self , device_json : dict , state_update_timestmp : datetime ):
119+ # When performing commands we might update the state temporary, need to ensure
120+ # that the state is not set back to something else if MyQ does not yet have updated
121+ # state
122+ last_update = self .device_json ["state" ].get ("last_update" )
123+ self .device_json = device_json
124+
125+ if (
126+ self .device_json ["state" ].get ("last_update" ) is not None
127+ and self .device_json ["state" ].get ("last_update" ) != last_update
128+ ):
129+ # MyQ has updated device state, reset ours ensuring we have the one from MyQ.
130+ self ._device_state = None
131+ _LOGGER .debug (
132+ "State for device %s was updated to %s" , self .name , self .state
133+ )
134+
135+ self .state_update = state_update_timestmp
136+
118137 async def _send_state_command (self , url : str , command : str ) -> None :
119138 """Instruct the API to change the state of the device."""
120139 # If the user tries to open or close, say, a gateway, throw an exception:
@@ -172,6 +191,6 @@ async def wait_for_state(
172191 # Reset self.state ensuring it reflects actual device state. Only do this if state is still what it would
173192 # have been, this to ensure if something else had updated it to something else we don't override.
174193 if self ._device_state == current_state :
175- self .state = None
194+ self ._device_state = None
176195
177196 return self .state in new_state
0 commit comments