Skip to content

Commit

Permalink
refactor is_online property
Browse files Browse the repository at this point in the history
  • Loading branch information
jziolkowski committed Sep 15, 2024
1 parent ccd7185 commit 52f1b71
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions tdmgr/GUI/dialogs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,15 @@ def mqtt_message(self, msg: Message):
if device := self.env.find_device(msg):
if msg.is_lwt:
log.debug("MQTT: LWT message for %s: %s", device.p["Topic"], msg.payload)
device.update_property("LWT", msg.payload)
device.online = msg.payload

if msg.payload == device.p["Online"]:
if device.online:
# known device came online, query initial state
self.initial_query(device, True)

else:
# forward the message for processing
device.update_property("LWT", device.p["Online"])
device.online = True
device.process_message(msg)

# TODO: ditto
Expand Down
2 changes: 1 addition & 1 deletion tdmgr/models/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def data(self, idx, role=Qt.DisplayRole):
return val

if role == DeviceRoles.LWTRole:
return d.is_online
return d.online

if role == DeviceRoles.RestartReasonRole:
return d.p.get("RestartReason")
Expand Down
2 changes: 1 addition & 1 deletion tdmgr/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def initial_commands():
commands = [(command, "") for command in commands]
commands += [("status", "0"), ("gpios", "255")]

for sht in range(4):
for sht in range(8):
commands.append([f"shutterrelay{sht + 1}", ""])
commands.append([f"shutterposition{sht + 1}", ""])

Expand Down
1 change: 0 additions & 1 deletion tdmgr/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def configure_logging(args) -> None:
elif args.log_location:
log_path = os.path.join(args.log_location, "tdm.log")


logging.basicConfig(
level="DEBUG" if args.debug else "INFO",
datefmt="%Y-%m-%d %H:%M:%S",
Expand Down
13 changes: 10 additions & 3 deletions tdmgr/tasmota/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ def power(self):
def shutters(self) -> dict:
return {
k: self.p[f"ShutterRelay{k}"]
for k in range(1, 5)
for k in range(1, 9)
if f"ShutterRelay{k}" in self.p and self.p[f"ShutterRelay{k}"] != 0
}

def shutter_positions(self) -> dict:
x = {k: self.p[f"Shutter{k}"] for k in range(1, 5) if f"Shutter{k}" in self.p}
x = {k: self.p[f"Shutter{k}"] for k in range(1, 9) if f"Shutter{k}" in self.p}
return x

def pwm(self):
Expand Down Expand Up @@ -335,9 +335,16 @@ def name(self):
return self.p["Topic"]

@property
def is_online(self):
def online(self):
return self.p.get("LWT", self.p["Offline"]) == self.p["Online"]

@online.setter
def online(self, val: Union[bool, dict]):
if isinstance(val, bool):
self.update_property("LWT", self.p["Online"])
else:
self.update_property("LWT", val)

@property
def url(self) -> Optional[str]:
if self.ip_address != "0.0.0.0":
Expand Down
Empty file removed tdmgr/util/__init__.py
Empty file.

0 comments on commit 52f1b71

Please sign in to comment.