Skip to content

Commit 70b956f

Browse files
author
amitlissack
authored
fix(tempdeck): make tempdeck waiting functions cancelable (#8327)
1 parent ebeced3 commit 70b956f

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

api/src/opentrons/hardware_control/modules/tempdeck.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,15 @@ async def set_temperature(self, celsius: float) -> None:
131131
"""
132132
await self.wait_for_is_running()
133133
await self._driver.set_temperature(celsius=celsius)
134-
# Wait until we reach the target temperature.
135-
while self.status != TemperatureStatus.HOLDING:
136-
await self.wait_next_poll()
134+
135+
async def _wait():
136+
# Wait until we reach the target temperature.
137+
while self.status != TemperatureStatus.HOLDING:
138+
await self.wait_next_poll()
139+
140+
task = self._loop.create_task(_wait())
141+
await self.make_cancellable(task)
142+
await task
137143

138144
async def start_set_temperature(self, celsius) -> None:
139145
"""
@@ -146,7 +152,7 @@ async def start_set_temperature(self, celsius) -> None:
146152
await self.wait_for_is_running()
147153
await self._driver.set_temperature(celsius)
148154

149-
async def await_temperature(self, awaiting_temperature: float):
155+
async def await_temperature(self, awaiting_temperature: float) -> None:
150156
"""
151157
Await temperature in degree Celsius
152158
Polls temperature module's temperature until
@@ -157,14 +163,17 @@ async def await_temperature(self, awaiting_temperature: float):
157163

158164
await self.wait_for_is_running()
159165

160-
if self.status == TemperatureStatus.HEATING:
161-
while self.temperature < awaiting_temperature:
162-
await self.wait_next_poll()
163-
elif self.status == TemperatureStatus.COOLING:
164-
while self.temperature > awaiting_temperature:
165-
await self.wait_next_poll()
166-
167-
return
166+
async def _await_temperature():
167+
if self.status == TemperatureStatus.HEATING:
168+
while self.temperature < awaiting_temperature:
169+
await self.wait_next_poll()
170+
elif self.status == TemperatureStatus.COOLING:
171+
while self.temperature > awaiting_temperature:
172+
await self.wait_next_poll()
173+
174+
t = self._loop.create_task(_await_temperature())
175+
await self.make_cancellable(t)
176+
await t
168177

169178
async def deactivate(self):
170179
"""Stop heating/cooling and turn off the fan"""

0 commit comments

Comments
 (0)