s-domotica-settings.lua /size: 5346 b    last modification: 2020-07-01 14:35
1if not modules then modules = { } end modules ['s-domotica-settings'] = {
2    version   = 1.001,
3    comment   = "companion to s-domotica-settings.mkiv",
4    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5    copyright = "PRAGMA ADE / ConTeXt Development Team",
6    license   = "see context related readme files"
7}
8
9moduledata.domotica          = moduledata.domotica          or { }
10moduledata.domotica.settings = moduledata.domotica.settings or { }
11
12-- bah, no proper wrapper around value|help
13
14moduledata.zwave = moduledata.zwave or { }
15moduledata.hue   = moduledata.hue   or { }
16
17local NC = context.NC
18local BC = context.BC
19local NR = context.NR
20
21function moduledata.zwave.show_settings(pattern)
22
23    local function show(setting)
24
25        context.starttabulate { "|r|r|r|r|l|p|" }
26            BC() context("index")
27         -- BC() context("genre")
28         -- BC() context("instance")
29            BC() context("value")
30            BC() context("min")
31            BC() context("max")
32            BC() context("type")
33            BC() context("label")
34            BC() NR()
35            for value in xml.collected(setting,"/Value") do
36                local at = value.at
37                NC() context(at.index)
38             -- NC() context(at.genre)
39             -- NC() context(at.instance)
40                NC() context(at.value)
41                NC() context(at.min)
42                NC() context(at.max)
43                NC() context(at.type)
44                NC() context.escaped(at.label)
45                NC() NR()
46           end
47        context.stoptabulate()
48
49    end
50
51    if string.find(pattern,"*",1,true) then
52
53        local list = dir.glob(pattern)
54        local last = nil
55
56        for i=1,#list do
57
58            local filename = list[i]
59            local root     = xml.load(filename)
60            local settings = xml.all(root,"/Product/CommandClass[@id='112']")
61
62            if settings then
63
64                local brand  = file.nameonly(file.pathpart(filename))
65                local device = file.nameonly(filename)
66
67                if last ~= brand then
68                    context.startchapter { title = brand }
69                end
70
71                context.startsection { title = device }
72                    for i=1,#settings do
73                        show(settings[i])
74                    end
75                context.stopsection()
76
77                if last ~= brand then
78                    last = brand
79                    context.stopchapter()
80                end
81
82            end
83
84        end
85
86    else
87
88        local root     = xml.load(pattern)
89        local settings = xml.all(root,"/Product/CommandClass[@id='112']")
90
91        if settings then
92            for i=1,#settings do
93                show(settings[i])
94            end
95        end
96
97    end
98
99end
100
101function moduledata.hue.show_state(filename)
102
103    require("control-common")
104    require("control-hue")
105
106    local specification = domotica.hue.check(filename)
107    local instances     = specification.instances
108
109    local ctx_NC, ctx_BC, ctx_NR = context.NC, context.BC, context.NR
110
111    for i=1,#instances do
112        local known = instances[i].knowndevices
113
114        if #instances > 1 then
115            context.subject("instance %i",i)
116        end
117
118        context.starttabulate { "|l|c|c|c|c|c|l|" }
119            ctx_BC() context("light name")
120            ctx_BC() context("id")
121            ctx_BC() context("state")
122            ctx_BC() context("level")
123            ctx_BC() context("color")
124            ctx_BC() context("seen")
125            ctx_BC() context("internal")
126            ctx_BC() ctx_NR()
127            for id, entry in table.sortedhash(known.lights) do
128                if entry.used then
129                    local state    = entry.state
130                    local name     = entry.name
131                    local internal = entry.internalname
132                    ctx_NC() context(entry.name)
133                    ctx_NC() context(entry.identifier)
134                    ctx_NC() context(state.on and "on " or "off")
135                    ctx_NC() context(state.brightness or 0)
136                    ctx_NC() context(state.temperature or 0)
137                    ctx_NC() context((state.reachable or entry.reachable) and "yes" or "no ")
138                    ctx_NC() if name == internal then context(name) else context.emphasized(internal) end
139                    ctx_NC() ctx_NR()
140                end
141            end
142        context.stoptabulate()
143        context.starttabulate { "|l|c|c|c|l|" }
144        ctx_BC() context("sensor name")
145        ctx_BC() context("id")
146        ctx_BC() context("seen")
147        ctx_BC() context("battery")
148        ctx_BC() context("internal")
149        ctx_BC() ctx_NR()
150        for id, entry in table.sortedhash(known.sensors) do
151            if entry.used then
152                local state    = entry.state
153                local name     = entry.name
154                local internal = entry.internalname
155                ctx_NC() context(name)
156                ctx_NC() context(entry.identifier)
157                ctx_NC() context((state.reachable or entry.reachable) and "yes" or "no ")
158                ctx_NC() context(entry.battery or "")
159                ctx_NC() if name == internal then context(name) else context.emphasized(internal) end
160                ctx_NC() ctx_NR()
161            end
162        end
163        context.stoptabulate()
164    end
165end
166