[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
11
HCDevice.py
11
HCDevice.py
@@ -43,9 +43,9 @@
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
import traceback
|
||||
import threading
|
||||
import time
|
||||
import traceback
|
||||
from base64 import urlsafe_b64encode as base64url_encode
|
||||
from datetime import datetime
|
||||
|
||||
@@ -338,7 +338,6 @@ class HCDevice:
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
threading.Thread(target=self.reconnect).start()
|
||||
else:
|
||||
self.print("Unknown resource", resource, file=sys.stderr)
|
||||
@@ -402,17 +401,21 @@ class HCDevice:
|
||||
def _on_message(ws, message):
|
||||
values = self.handle_message(message)
|
||||
on_message(values)
|
||||
|
||||
def _on_open(ws):
|
||||
self.connected = True
|
||||
on_open(ws)
|
||||
|
||||
def _on_close(ws, code, message):
|
||||
self.connected = False
|
||||
on_close(ws, code, message)
|
||||
|
||||
def on_error(ws, message):
|
||||
self.print("Websocket error:", message)
|
||||
|
||||
self.ws.run_forever(on_message=_on_message, on_open=_on_open, on_close=_on_close,
|
||||
on_error=on_error)
|
||||
self.ws.run_forever(
|
||||
on_message=_on_message, on_open=_on_open, on_close=_on_close, on_error=on_error
|
||||
)
|
||||
|
||||
def print(self, *args):
|
||||
print(now(), self.name, *args)
|
||||
|
||||
13
HCSocket.py
13
HCSocket.py
@@ -201,12 +201,13 @@ class HCSocket:
|
||||
|
||||
print(now(), "CON:", self.uri)
|
||||
self.ws = websocket.WebSocketApp(
|
||||
self.uri,
|
||||
socket=sock,
|
||||
on_open=_on_open,
|
||||
on_message=_on_message,
|
||||
on_close=_on_close,
|
||||
on_error=_on_error)
|
||||
self.uri,
|
||||
socket=sock,
|
||||
on_open=_on_open,
|
||||
on_message=_on_message,
|
||||
on_close=_on_close,
|
||||
on_error=_on_error,
|
||||
)
|
||||
|
||||
websocket.setdefaulttimeout(30)
|
||||
|
||||
|
||||
@@ -139,6 +139,7 @@ def hc2mqtt(
|
||||
global dev
|
||||
dev = {}
|
||||
|
||||
|
||||
def client_connect(client, device, mqtt_topic):
|
||||
host = device["host"]
|
||||
name = device["name"]
|
||||
@@ -201,5 +202,6 @@ def client_connect(client, device, mqtt_topic):
|
||||
|
||||
time.sleep(57)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
hc2mqtt()
|
||||
|
||||
Reference in New Issue
Block a user