Skip to content

Commit

Permalink
Various cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jackbrown1993 committed Nov 12, 2024
1 parent 3849e70 commit 4ac0756
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
12 changes: 10 additions & 2 deletions app/docker_mqtt_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def on_connect(mqttc, obj, flags, rc):
# Subscribe to all MQTT jacuzzi topics
mqtt_client.subscribe("jacuzzi/#")

def on_disconnect(mqttc, obj, rc):
"""This is triggered whenever we disconnect fromm MQTT"""
log.info("Disconnected MQTT broker.")


def on_message(mqttc, obj, msg):
"""This is triggered whenever we receive a message on MQTT"""
Expand Down Expand Up @@ -104,7 +108,10 @@ async def read_spa_data(spa, lastupd):
if spa.lastupd != lastupd:
lastupd = spa.lastupd
log.info(
f"Jacuzzi temperature is set to {spa.get_settemp()}, actual temperature is {spa.curtemp}"
f"Spa date: {spa.get_spadate()}\n"
f"Spa time: {spa.get_spatime()}\n"
f"Water temp: {spa.curtemp}\n"
f"Set Temp: {spa.get_settemp()}"
)

# Last update
Expand All @@ -115,7 +122,7 @@ async def read_spa_data(spa, lastupd):
retain=True,
)

# Set Temp
# Connection Status
mqtt_client.publish(
"jacuzzi/connection/status",
payload="1" if spa.connection_state.name == "Connected" else "0",
Expand Down Expand Up @@ -179,6 +186,7 @@ async def start_mqtt():
mqtt_client = mqtt.Client("jacuzzi_rs485")
mqtt_client.username_pw_set(username=mqtt_user, password=mqtt_password)
mqtt_client.on_connect = on_connect
mqtt_client.on_disconnect = on_disconnect
mqtt_client.on_message = on_message
mqtt_client.connect(mqtt_ip, mqtt_port)
mqtt_client.loop_start()
Expand Down
23 changes: 17 additions & 6 deletions app/jacuzziRS485.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,9 @@ async def check_connection_status(self):
# send the spa a message to see if it will respond.

if self.channel is not None and time.time() > self.lastupd + timeout:
self.log.info("No update from spa in {} seconds. Setting connection status to Disconnected", timeout)
self.connection_state = ConnectionStates.Disconnected
self.log.info("Requesting module ID.")
self.log.info("Requesting module ID to see if we can get response from spa.")
await self.send_mod_ident_req()

self.lastupd = time.time()
Expand All @@ -1000,7 +1001,7 @@ async def listen(self):

while True:
if not self.connected:
# sleep and hope the checker fixes us
# Sleep before checking if we are connected again
await asyncio.sleep(5)
continue

Expand Down Expand Up @@ -1153,10 +1154,15 @@ async def listen_until_configured(self, maxiter=20):

def get_connection_state_text(self):
return "{0} (Channel: {1})".format(self.connection_state.name, self.channel)

def get_spatime(self):
return "{0:02d}:{1:02d}".format(
self.time_hour, self.time_minute
)

def get_spatime_text(self):
return "Spa Time: {0:02d}:{1:02d} {2}".format(
self.time_hour, self.time_minute, self.get_timescale(True)
return "Spa Time: {0} {1}".format(
self.get_spatime(), self.get_timescale(True)
)

def get_day(self):
Expand All @@ -1167,10 +1173,15 @@ def get_month(self):

def get_year(self):
return self.currentYear

def get_spadate(self):
return "{0}/{1}/{2}".format(
self.get_month(), self.get_day(), self.get_year()
)

def get_spadate_text(self):
return "Spa Date: {0}/{1}/{2}".format(
self.get_month(), self.get_day(), self.get_year()
return "Spa Date: {0}".format(
self.get_spadate()
)

def get_curtemp_text(self):
Expand Down

0 comments on commit 4ac0756

Please sign in to comment.