introduce black formater

This commit is contained in:
Ingolf Wagner 2021-03-26 02:46:05 +01:00
parent 8c5b946081
commit 0d7975f31f
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
3 changed files with 38 additions and 25 deletions

View file

@ -16,7 +16,6 @@ class Position(Enum):
class Fyrtur: class Fyrtur:
def __init__(self, topic, top, bottom): def __init__(self, topic, top, bottom):
self.topic = topic self.topic = topic
self.top = top self.top = top
@ -55,7 +54,9 @@ class FyrturWatcher:
elif position == Position.DOWN: elif position == Position.DOWN:
fyrtur.wanted_position = fyrtur.bottom fyrtur.wanted_position = fyrtur.bottom
elif position == Position.HALF: elif position == Position.HALF:
fyrtur.wanted_position = round((fyrtur.top - fyrtur.bottom) / 2 + fyrtur.bottom) fyrtur.wanted_position = round(
(fyrtur.top - fyrtur.bottom) / 2 + fyrtur.bottom
)
def publish(self, client): def publish(self, client):
for fyrtur in self.fyrturs.values(): for fyrtur in self.fyrturs.values():
@ -65,11 +66,13 @@ class FyrturWatcher:
time.sleep(2) time.sleep(2)
watcher = FyrturWatcher({ watcher = FyrturWatcher(
{
"office1": Fyrtur(topic="zigbee2mqtt/office_fyrtur_1", top=100, bottom=16), "office1": Fyrtur(topic="zigbee2mqtt/office_fyrtur_1", top=100, bottom=16),
"office2": Fyrtur(topic="zigbee2mqtt/office_fyrtur_2", top=100, bottom=22), "office2": Fyrtur(topic="zigbee2mqtt/office_fyrtur_2", top=100, bottom=22),
"bedroom": Fyrtur(topic="zigbee2mqtt/bedroom_fyrtur_1", top=100, bottom=16), "bedroom": Fyrtur(topic="zigbee2mqtt/bedroom_fyrtur_1", top=100, bottom=16),
}) }
)
# The callback for when the client receives a CONNACK response from the server. # The callback for when the client receives a CONNACK response from the server.
@ -90,8 +93,8 @@ def on_message(client, _userdata, msg):
global scene global scene
(topic, payload) = parse_message(msg) (topic, payload) = parse_message(msg)
if topic == "control/lights/set": if topic == "control/lights/set":
print("set scene %s -> %s" % (scene, payload['scene'])) print("set scene %s -> %s" % (scene, payload["scene"]))
scene = payload['scene'] scene = payload["scene"]
update_scene(client) update_scene(client)
else: else:
print("got %s" % topic) print("got %s" % topic)

View file

@ -23,9 +23,14 @@ class Heater:
if self.not_initialized_yet: if self.not_initialized_yet:
self.not_initialized_yet = False self.not_initialized_yet = False
self.wanted_temperature = heating_setpoint self.wanted_temperature = heating_setpoint
print("%s: update wanted temperature %d" % (self.topic, self.actual_temperature)) print(
"%s: update wanted temperature %d"
% (self.topic, self.actual_temperature)
)
self.actual_temperature = heating_setpoint self.actual_temperature = heating_setpoint
print("%s: update actual temperature %d" % (self.topic, self.actual_temperature)) print(
"%s: update actual temperature %d" % (self.topic, self.actual_temperature)
)
def topic_and_payload_for_query(self): def topic_and_payload_for_query(self):
payload = { payload = {
@ -33,24 +38,23 @@ class Heater:
"occupied_heating_setpoint": "", "occupied_heating_setpoint": "",
"unoccupied_heating_setpoint": "", "unoccupied_heating_setpoint": "",
"local_temperature": "", "local_temperature": "",
#"pi_heating_demand": "", # "pi_heating_demand": "",
#"system_mode": "", # "system_mode": "",
} }
return ("%s/get" % self.topic), json.dumps(payload) return ("%s/get" % self.topic), json.dumps(payload)
def topic_and_payload_for_set(self): def topic_and_payload_for_set(self):
payload = { payload = {
"system_mode": "auto", "system_mode": "auto",
#"current_heating_setpoint": str(self.wanted_temperature), # "current_heating_setpoint": str(self.wanted_temperature),
"occupied_heating_setpoint": str(self.wanted_temperature), "occupied_heating_setpoint": str(self.wanted_temperature),
"unoccupied_heating_setpoint": str(self.wanted_temperature), "unoccupied_heating_setpoint": str(self.wanted_temperature),
"eurotronic_host_flags": {"window_open": True} "eurotronic_host_flags": {"window_open": True},
} }
return ("%s/set" % self.topic), json.dumps(payload) return ("%s/set" % self.topic), json.dumps(payload)
class Watcher: class Watcher:
def __init__(self, heater: Dict[str, Heater]): def __init__(self, heater: Dict[str, Heater]):
self.heater = heater self.heater = heater
@ -82,12 +86,14 @@ class Watcher:
scene = "default" scene = "default"
watcher = Watcher({ watcher = Watcher(
{
"office1": Heater(topic="zigbee2mqtt/office_heater_1"), "office1": Heater(topic="zigbee2mqtt/office_heater_1"),
"office2": Heater(topic="zigbee2mqtt/office_heater_2"), "office2": Heater(topic="zigbee2mqtt/office_heater_2"),
"bedroom": Heater(topic="zigbee2mqtt/bedroom_heater_1"), "bedroom": Heater(topic="zigbee2mqtt/bedroom_heater_1"),
"storage": Heater(topic="zigbee2mqtt/storage_heater_1"), "storage": Heater(topic="zigbee2mqtt/storage_heater_1"),
}) }
)
# The callback for when the client receives a CONNACK response from the server. # The callback for when the client receives a CONNACK response from the server.
@ -109,8 +115,8 @@ def on_message(client, _userdata, msg):
global scene global scene
(topic, payload) = parse_message(msg) (topic, payload) = parse_message(msg)
if topic == "control/lights/set": if topic == "control/lights/set":
print("set scene %s -> %s" % (scene, payload['scene'])) print("set scene %s -> %s" % (scene, payload["scene"]))
scene = payload['scene'] scene = payload["scene"]
update_scene(client) update_scene(client)
else: else:
print("got %s" % topic) print("got %s" % topic)

View file

@ -8,8 +8,12 @@ let
${myPython}/bin/python ./heater.py ${myPython}/bin/python ./heater.py
''; '';
reformat = pkgs.writers.writeBashBin "reformat" ''
${pkgs.black}/bin/black --exclude venv ${toString ./.}
'';
in pkgs.mkShell { in pkgs.mkShell {
buildInputs = with pkgs; [ myPython startServer ]; buildInputs = with pkgs; [ myPython startServer reformat ];
} }