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:
def __init__(self, topic, top, bottom):
self.topic = topic
self.top = top
@ -55,7 +54,9 @@ class FyrturWatcher:
elif position == Position.DOWN:
fyrtur.wanted_position = fyrtur.bottom
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):
for fyrtur in self.fyrturs.values():
@ -65,11 +66,13 @@ class FyrturWatcher:
time.sleep(2)
watcher = FyrturWatcher({
watcher = FyrturWatcher(
{
"office1": Fyrtur(topic="zigbee2mqtt/office_fyrtur_1", top=100, bottom=16),
"office2": Fyrtur(topic="zigbee2mqtt/office_fyrtur_2", top=100, bottom=22),
"bedroom": Fyrtur(topic="zigbee2mqtt/bedroom_fyrtur_1", top=100, bottom=16),
})
}
)
# 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
(topic, payload) = parse_message(msg)
if topic == "control/lights/set":
print("set scene %s -> %s" % (scene, payload['scene']))
scene = payload['scene']
print("set scene %s -> %s" % (scene, payload["scene"]))
scene = payload["scene"]
update_scene(client)
else:
print("got %s" % topic)

View file

@ -23,9 +23,14 @@ class Heater:
if self.not_initialized_yet:
self.not_initialized_yet = False
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
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):
payload = {
@ -44,13 +49,12 @@ class Heater:
# "current_heating_setpoint": str(self.wanted_temperature),
"occupied_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)
class Watcher:
def __init__(self, heater: Dict[str, Heater]):
self.heater = heater
@ -82,12 +86,14 @@ class Watcher:
scene = "default"
watcher = Watcher({
watcher = Watcher(
{
"office1": Heater(topic="zigbee2mqtt/office_heater_1"),
"office2": Heater(topic="zigbee2mqtt/office_heater_2"),
"bedroom": Heater(topic="zigbee2mqtt/bedroom_heater_1"),
"storage": Heater(topic="zigbee2mqtt/storage_heater_1"),
})
}
)
# 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
(topic, payload) = parse_message(msg)
if topic == "control/lights/set":
print("set scene %s -> %s" % (scene, payload['scene']))
scene = payload['scene']
print("set scene %s -> %s" % (scene, payload["scene"]))
scene = payload["scene"]
update_scene(client)
else:
print("got %s" % topic)

View file

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