Skip to content

Commit

Permalink
- Add connect() for socket
Browse files Browse the repository at this point in the history
- Switch from zope to simple callback
- De-lint
  • Loading branch information
swilson committed Sep 27, 2018
1 parent f4932f9 commit fec18e2
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 109 deletions.
42 changes: 17 additions & 25 deletions aqualogic/cli.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,36 @@
"""aqualogic command line test app."""

from core import AquaLogic, Keys, States
import zope.event
import socket
import threading
import logging
import sys
from core import AquaLogic, States

logging.basicConfig(level=logging.INFO)
PORT = 23


def data_changed(aq):
print('Pool Temp: {}'.format(aq.pool_temp))
print('Air Temp: {}'.format(aq.air_temp))
print('Pump Speed: {}'.format(aq.pump_speed))
print('Pump Power: {}'.format(aq.pump_power))
print('States: {}'.format(aq.states()))
if aq.get_state(States.CHECK_SYSTEM):
print('Check System: {}'.format(aq.check_system_msg))
def _data_changed(panel):
print('Pool Temp: {}'.format(panel.pool_temp))
print('Air Temp: {}'.format(panel.air_temp))
print('Pump Speed: {}'.format(panel.pump_speed))
print('Pump Power: {}'.format(panel.pump_power))
print('States: {}'.format(panel.states()))
if panel.get_state(States.CHECK_SYSTEM):
print('Check System: {}'.format(panel.check_system_msg))


PANEL = AquaLogic()
print('Connecting to {}:{}...'.format(sys.argv[1], PORT))
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((sys.argv[1], PORT))
reader = s.makefile(mode='rb')
writer = s.makefile(mode='wb')
PANEL.connect(sys.argv[1], PORT)
print('Connected!')

aq = AquaLogic(reader, writer)

zope.event.subscribers.append(data_changed)

reader_thread = threading.Thread(target=aq.process)
reader_thread.start()
READER_THREAD = threading.Thread(target=PANEL.process, args=[_data_changed])
READER_THREAD.start()

while True:
line = input()
LINE = input()
try:
state = States[line]
aq.set_state(state, not aq.get_state(state))
STATE = States[LINE]
PANEL.set_state(STATE, not PANEL.get_state(STATE))
except KeyError:
print('Invalid key {}'.format(line))
print('Invalid key {}'.format(LINE))
Loading

0 comments on commit fec18e2

Please sign in to comment.