Skip to content

Commit

Permalink
Add firmware version to device
Browse files Browse the repository at this point in the history
  • Loading branch information
aneisch committed May 8, 2024
1 parent 42247fb commit 031bf1d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions thermostat_api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
thermostat_state_topic = f"homeassistant/climate/{thermostat_name}/state"
thermostat_serial = os.environ['THERMOSTAT_SERIAL']

device = {"mdl": "TSTAT0201CW", "mf": "Observer", "ids": thermostat_serial, "name": thermostat_name}
device = {"mdl": "TSTAT0201CW", "sw": None, "mf": "Observer", "ids": thermostat_serial, "name": thermostat_name}

climate_configuration_payload = {
"act_t": thermostat_state_topic,
Expand Down Expand Up @@ -325,7 +325,7 @@ def do_POST(self):
html = ""
match = False
monitored = ["rt","rh","mode","fan","coolicon","heaticon","fanicon","hold","filtrlvl","clsp","htsp","opstat","iducfm","oat","oducoiltmp"]
paths = ["/status", "/odu_status","/equipment_events"] # we only need data from these paths
paths = ["/status", "/odu_status","/equipment_events", "/profile"] # we only need data from these paths
received_message = {}
final_locator = f'/{self.path.split("/")[-1:][0]}' # eg /status
logging.debug(f"{final_locator} -- {data}")
Expand Down Expand Up @@ -370,6 +370,16 @@ def do_POST(self):
current_configuration["latest_equip"] = state
self.send_empty_200()

elif "/profile" in final_locator:
# Attempt to grab FW version and update climate device
try:
if climate_configuration_payload["device"]["sw"] != received_message['firmware']:
climate_configuration_payload["device"]["sw"] = f"{received_message['firmware']}"
client.publish(f'homeassistant/climate/{thermostat_serial}-climate/config', json.dumps(climate_configuration_payload), retain=True)
except:
pass
self.send_empty_200()

elif "/status" in final_locator:
logging.debug(f"Current Configuration: {current_configuration}")
current_configuration["last_communication"] = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
Expand Down

0 comments on commit 031bf1d

Please sign in to comment.