Skip to content

Commit

Permalink
Try to handle raced with hub error reports and hub restarts gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkahn committed Jan 28, 2025
1 parent e8411dc commit f69a2f9
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 19 deletions.
13 changes: 3 additions & 10 deletions .idea/deployment.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions .idea/runConfigurations/Development.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/softconsole.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gitver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
committime = "Thu Jan 2 13:45:28 2025"
commitseq = 50
committime = "Tue Jan 28 14:25:50 2025"
commitseq = 51
extratest = 'ablc'

3 changes: 2 additions & 1 deletion hubs/ha/haremote.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ def call_service(api: API, domain: str, service: str, service_data: Dict = None,
return

except HomeAssistantError as e:
logsupport.Logs.Log("HA service call failed ({}) timeout: {} exc: {}".format(tryit, timeout, repr(e)),
logsupport.Logs.Log(
f"HA svc call {tryit} failed for {domain}.{service}({service_data}) T/O:{timeout}): {e}",
severity=logsupport.ConsoleWarning if tryit == 'retry' else logsupport.ConsoleInfo)
if tryit == 'retry':
raise
Expand Down
12 changes: 9 additions & 3 deletions hubs/ha/hasshub.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ def Announce(self):
config.MQTTBroker.PublishRawJSON(target, discovery, retain=True)

def HubLog(self, code=-1, message=None):
if config.MQTTBroker is None:
logsupport.Logs.Log(f"Can't issue HubLog until MQTT is running - Code: {code} Message: {message}")
return
if code != -1 and self.LastErrorCode == -1:
# handle odd case where first log message isn't logged by HA?
logmess = {"logitem": "Error indicator set", "errorcode": code}
Expand All @@ -525,9 +528,12 @@ def HubLog(self, code=-1, message=None):
config.MQTTBroker.PublishRawJSON(f"{self.name}/{hw.hostname}/errstate", logmess, retain=True)
self.LastErrorCode = code
if code == -1:
ha.call_service(self.api, 'recorder', 'purge_entities',
{'entity_id': f"sensor.{hw.hostname}_logitem".replace('-', '_')})
logsupport.Logs.Log(f"sensor.{hw.hostname}_logitem")
try:
ha.call_service(self.api, 'recorder', 'purge_entities',
{'entity_id': f"sensor.{hw.hostname}_logitem".replace('-', '_')})
logsupport.Logs.Log(f"sensor.{hw.hostname}_logitem")
except Exception as E:
logsupport.Logs.Log(f"Failed purge call for sensor.{hw.hostname}_logitem: {E}")

def HAevents(self):

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Thu Jan 2 13:45:28 2025/50
#Tue Jan 28 14:25:50 2025/51
configobj~=5.0.8
webcolors~=1.13
xmltodict~=0.13.0
Expand Down

0 comments on commit f69a2f9

Please sign in to comment.