Reading light level and showing it on light level page

This commit is contained in:
Daniele Verducci 2024-04-19 08:46:21 +02:00
parent 30ab14f278
commit 953f76f233
3 changed files with 13 additions and 7 deletions

View File

@ -39,5 +39,6 @@ class SensorsPollingTimer(Timer):
value = self.proxy.Get('(ss)', 'net.hadess.SensorProxy', 'LightLevel') value = self.proxy.Get('(ss)', 'net.hadess.SensorProxy', 'LightLevel')
if (self.oldValue != value): if (self.oldValue != value):
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

View File

@ -25,15 +25,20 @@ from .sensors_polling_timer import SensorsPollingTimer
class LumosWindow(Adw.ApplicationWindow): class LumosWindow(Adw.ApplicationWindow):
__gtype_name__ = 'LumosWindow' __gtype_name__ = 'LumosWindow'
#label = Gtk.Template.Child() lux_label = Gtk.Template.Child()
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
# Start polling sensors # Start polling sensors
self.sensorsPollingTimer = SensorsPollingTimer(1, self.onSensorRead) self.sensorsPollingTimer = SensorsPollingTimer(0.1, self.onSensorRead)
self.sensorsPollingTimer.run() self.sensorsPollingTimer.start()
def onSensorRead(self, value): def onSensorRead(self, value, unit):
# Called when the light value changed # 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))

View File

@ -89,7 +89,7 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkLabel" id="lux-label"> <object class="GtkLabel" id="lux_label">
<property name="label" translatable="no">XXX Lux</property> <property name="label" translatable="no">XXX Lux</property>
<style> <style>
<class name="title-1"/> <class name="title-1"/>