From 953f76f23343d190b0312c02c6540ba880309055 Mon Sep 17 00:00:00 2001 From: Daniele Verducci Date: Fri, 19 Apr 2024 08:46:21 +0200 Subject: [PATCH] Reading light level and showing it on light level page --- src/sensors_polling_timer.py | 3 ++- src/window.py | 15 ++++++++++----- src/window.ui | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/sensors_polling_timer.py b/src/sensors_polling_timer.py index f0d872c..cfbf260 100644 --- a/src/sensors_polling_timer.py +++ b/src/sensors_polling_timer.py @@ -39,5 +39,6 @@ class SensorsPollingTimer(Timer): value = self.proxy.Get('(ss)', 'net.hadess.SensorProxy', 'LightLevel') if (self.oldValue != value): self.oldValue = value - self.function(value) # Invoke callback + unit = self.proxy.Get('(ss)', 'net.hadess.SensorProxy', 'LightLevelUnit') + self.function(value, unit) # Invoke callback diff --git a/src/window.py b/src/window.py index 7d3577b..9ae01fe 100644 --- a/src/window.py +++ b/src/window.py @@ -25,15 +25,20 @@ from .sensors_polling_timer import SensorsPollingTimer class LumosWindow(Adw.ApplicationWindow): __gtype_name__ = 'LumosWindow' - #label = Gtk.Template.Child() + lux_label = Gtk.Template.Child() def __init__(self, **kwargs): super().__init__(**kwargs) # Start polling sensors - self.sensorsPollingTimer = SensorsPollingTimer(1, self.onSensorRead) - self.sensorsPollingTimer.run() + self.sensorsPollingTimer = SensorsPollingTimer(0.1, self.onSensorRead) + self.sensorsPollingTimer.start() - def onSensorRead(self, value): + def onSensorRead(self, value, unit): # Called when the light value changed - print("Read {} lux".format(value)) + print("Read {} {}".format(value, unit)) + + if self.lux_label: + self.lux_label.set_label("{:.0f} {}".format(value, unit)) + + diff --git a/src/window.ui b/src/window.ui index fa719a4..eca74a4 100644 --- a/src/window.ui +++ b/src/window.ui @@ -89,7 +89,7 @@ - + XXX Lux