Reading light level and showing it on light level page
This commit is contained in:
parent
30ab14f278
commit
953f76f233
@ -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
|
||||
|
||||
|
@ -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))
|
||||
|
||||
|
||||
|
@ -89,7 +89,7 @@
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="lux-label">
|
||||
<object class="GtkLabel" id="lux_label">
|
||||
<property name="label" translatable="no">XXX Lux</property>
|
||||
<style>
|
||||
<class name="title-1"/>
|
||||
|
Loading…
Reference in New Issue
Block a user