Skip to content

Commit

Permalink
Allowing CLI arguments to override device config on --resume-session
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis-chambers committed Aug 8, 2024
1 parent 058aa86 commit 9931e44
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/iotswarm/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,13 @@ async def run(self):
message_connection: The message object to send data through
"""

if self.delay_start:
await self._add_delay()

while True:
if self.max_cycles > 0 and self.cycle >= self.max_cycles:
break

if self.delay_start and self.cycle == 0:
await self._add_delay()

payload = await self._get_payload()

if payload is not None:
Expand Down
14 changes: 14 additions & 0 deletions src/iotswarm/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,17 @@ async def _mqtt_resume_session():

for i in range(len(swarm.devices)):
swarm.devices[i].connection = connection
swarm.devices[i].delay_start = delay_start
swarm.devices[i].device_type = device_type

if max_cycles is not None:
swarm.devices[i].max_cycles = max_cycles
if sleep_time is not None:
swarm.devices[i].sleep_time = sleep_time
if mqtt_prefix is not None:
swarm.devices[i].mqtt_prefix = mqtt_prefix
if mqtt_suffix is not None:
swarm.devices[i].mqtt_suffix = mqtt_suffix

click.echo("Loaded swarm from pickle")

Expand Down Expand Up @@ -454,10 +461,17 @@ async def _mqtt_resume_session():

for i in range(len(swarm.devices)):
swarm.devices[i].connection = connection
swarm.devices[i].delay_start = delay_start
swarm.devices[i].device_type = device_type

if max_cycles is not None:
swarm.devices[i].max_cycles = max_cycles
if sleep_time is not None:
swarm.devices[i].sleep_time = sleep_time
if mqtt_prefix is not None:
swarm.devices[i].mqtt_prefix = mqtt_prefix
if mqtt_suffix is not None:
swarm.devices[i].mqtt_suffix = mqtt_suffix

click.echo(swarm.devices[0].cycle)
click.echo("Loaded swarm from pickle")
Expand Down

0 comments on commit 9931e44

Please sign in to comment.