Skip to content

Commit c06c819

Browse files
committed
fix Shutdown, add ignore to disk_io
1 parent e4ca2c9 commit c06c819

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

lnxlink/modules/disk_io.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _get_disks(self):
6969
disks = []
7070
for disk in glob.glob("/sys/block/*", recursive=False):
7171
disk_name = disk.removeprefix("/sys/block/")
72-
excludes = ["loop", "ram"]
72+
excludes = ["loop", "ram", "zram"]
7373
if any(disk_name.startswith(x) for x in excludes):
7474
continue
7575
disks.append(disk_name)

lnxlink/modules/shutdown.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,23 @@ def __init__(self, lnxlink):
1919
def start_control(self, topic, data):
2020
"""Control system"""
2121
self.lnxlink.temp_connection_callback(True)
22-
if which("systemctl") is not None:
23-
syscommand("systemctl poweroff")
24-
elif which("shutdown") is not None:
25-
syscommand("shutdown now")
26-
else:
27-
bus = self.dbus.connection.SystemMessageBus()
28-
proxy = bus.get_proxy(
29-
service_name="org.freedesktop.login1",
30-
object_path="/org/freedesktop/login1",
31-
)
32-
proxy.PowerOff(True)
22+
returncode = None
23+
if which("systemctl") is not None and returncode != 0:
24+
_, _, returncode = syscommand("systemctl poweroff")
25+
if which("shutdown") is not None and returncode != 0:
26+
_, _, returncode = syscommand("shutdown now")
27+
if returncode != 0:
28+
try:
29+
bus = self.dbus.connection.SystemMessageBus()
30+
proxy = bus.get_proxy(
31+
service_name="org.freedesktop.login1",
32+
object_path="/org/freedesktop/login1",
33+
)
34+
proxy.PowerOff(True)
35+
except Exception:
36+
returncode = -1
37+
if returncode != 0:
38+
self.lnxlink.temp_connection_callback(False)
3339

3440
def exposed_controls(self):
3541
"""Exposes to home assistant"""

0 commit comments

Comments
 (0)