Skip to content

Commit

Permalink
Merge pull request #42 from tronikos/main
Browse files Browse the repository at this point in the history
Create send_to_posix_queue to avoid duplicate code
  • Loading branch information
tronikos authored Dec 23, 2023
2 parents bf9e25a + 8a2b912 commit 7f68f13
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions mqtt-bridge/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,24 @@ def redis_hmget(name, keys):
syscall = libc.syscall


def send_to_posix_queue(name, msg):
mq = syscall(274, name, 0x2, 0x1C7, None)
if mq < 0:
return
syscall(276, mq, msg.ljust(1024, b"\x00"), 1024, 0, None)
os.close(mq)


def pause_resume(val):
proposed_state = int(val)
current_state = sql_execute("SELECT `charging_enable` FROM wallbox_config;")["charging_enable"]
if proposed_state == current_state:
return

mq = syscall(274, b"WALLBOX_MYWALLBOX_WALLBOX_STATEMACHINE", 0x2, 0x1C7, None)
if mq < 0:
return
if proposed_state == 1:
syscall(276, mq, b"EVENT_REQUEST_USER_ACTION#1.000000".ljust(1024, b"\x00"), 1024, 0, None)
send_to_posix_queue(b"WALLBOX_MYWALLBOX_WALLBOX_STATEMACHINE", b"EVENT_REQUEST_USER_ACTION#1.000000")
elif proposed_state == 0:
syscall(276, mq, b"EVENT_REQUEST_USER_ACTION#2.000000".ljust(1024, b"\x00"), 1024, 0, None)
os.close(mq)
send_to_posix_queue(b"WALLBOX_MYWALLBOX_WALLBOX_STATEMACHINE", b"EVENT_REQUEST_USER_ACTION#2.000000")


# Needed for unlock
Expand All @@ -139,14 +143,10 @@ def lock_unlock(val):
if proposed_state == current_state:
return

mq = syscall(274, b"WALLBOX_MYWALLBOX_WALLBOX_LOGIN", 0x2, 0x1C7, None)
if mq < 0:
return
if proposed_state == 1:
syscall(276, mq, b"EVENT_REQUEST_LOCK".ljust(1024, b"\x00"), 1024, 0, None)
send_to_posix_queue(b"WALLBOX_MYWALLBOX_WALLBOX_LOGIN", b"EVENT_REQUEST_LOCK")
elif proposed_state == 0:
syscall(276, mq, (b"EVENT_REQUEST_LOGIN#%d.000000" % wallbox_uid).ljust(1024, b"\x00"), 1024, 0, None)
os.close(mq)
send_to_posix_queue(b"WALLBOX_MYWALLBOX_WALLBOX_LOGIN", (b"EVENT_REQUEST_LOGIN#%d.000000" % wallbox_uid))


# Applies some additional rules to the internal state and returns the status as a string
Expand Down

0 comments on commit 7f68f13

Please sign in to comment.