Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
fixed state modification issue
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamah committed Feb 10, 2020
1 parent ee50718 commit 6b4f9f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def debug_show(state):
if state != previous_state:
previous_state = copy.deepcopy(state)

utils.update_state_with_device_name(state, CONSTANTS.CPX)
message = utils.create_message(state)
state_copy = utils.update_state_with_device_name(state, CONSTANTS.CPX)
message = utils.create_message(state_copy)

update_state(json.dumps(message))

Expand Down
12 changes: 8 additions & 4 deletions src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@


def update_state_with_device_name(state, device_name):
state_copy = dict(state)

state_ext = {
"device_name": device_name,
}
state.update(state_ext)
state_copy.update(state_ext)

return state_copy


def create_message(state_copy):
Expand All @@ -25,11 +29,11 @@ def create_message(state_copy):
def send_to_simulator(state, device_name):
global previous_state

update_state_with_device_name(state, device_name)
message = create_message(state)
state_copy = update_state_with_device_name(state, device_name)
message = create_message(state_copy)

if state != previous_state:
previous_state = copy.deepcopy(state)
previous_state = copy.deepcopy(state_copy)
print(json.dumps(message) + "\0", end="", file=sys.__stdout__, flush=True)
time.sleep(CONSTANTS.TIME_DELAY)

Expand Down

0 comments on commit 6b4f9f1

Please sign in to comment.