-
Notifications
You must be signed in to change notification settings - Fork 2
/
OWSensor.lua
51 lines (45 loc) · 1.32 KB
/
OWSensor.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class 'OWSensor' (QuickAppChild)
OWSensor.class = 'com.fibaro.multilevelSensor'
function OWSensor:__init(device)
self.device = false
QuickAppChild.__init(self, device)
end
function OWSensor:get(name, class)
if Toggles:get(name) then
if not class then
class = self.class
end
local id = 'openweather-' .. name
local label = QuickApp.i18n:get(id)
local options = {
manufacturer = 'OpenWeather',
model = name:sub(1, 1):upper() .. name:sub(2) .. ' sensor'
}
self.device = QuickApp.builder:updateChild(id, label, class, options)
else
self:delete(name)
self.device = false
end
return self
end
function OWSensor:delete(name)
if not Toggles:get(name) then
-- QuickApp:debug('Deleting ', name)
QuickApp.builder:deleteChild('openweather-' .. name)
end
end
function OWSensor:update(properties)
if self.device == nil or not self.device then
return false
end
if type(properties) ~= 'table' then
properties = {
value = properties
}
end
for name, value in pairs(properties) do
self.device:updateProperty(name, value)
end
QuickApp:trace(string.format(QuickApp.i18n:get('device-updated'), self.device.name))
return true
end