introduce black formater
This commit is contained in:
parent
8c5b946081
commit
0d7975f31f
3 changed files with 38 additions and 25 deletions
|
@ -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({
|
||||
"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),
|
||||
})
|
||||
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)
|
||||
|
|
|
@ -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 = {
|
||||
|
@ -33,24 +38,23 @@ class Heater:
|
|||
"occupied_heating_setpoint": "",
|
||||
"unoccupied_heating_setpoint": "",
|
||||
"local_temperature": "",
|
||||
#"pi_heating_demand": "",
|
||||
#"system_mode": "",
|
||||
# "pi_heating_demand": "",
|
||||
# "system_mode": "",
|
||||
}
|
||||
return ("%s/get" % self.topic), json.dumps(payload)
|
||||
|
||||
def topic_and_payload_for_set(self):
|
||||
payload = {
|
||||
"system_mode": "auto",
|
||||
#"current_heating_setpoint": str(self.wanted_temperature),
|
||||
# "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({
|
||||
"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"),
|
||||
})
|
||||
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)
|
||||
|
|
|
@ -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 ];
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue