Skip to content

Commit acd218b

Browse files
committed
Adds eventtitle config to distinguish same titled panels
Adds duplicate id protection
1 parent 6e42370 commit acd218b

13 files changed

+43
-8
lines changed

config/big-sample-config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ GlowDash:
1818
Panels: # You can define panels here
1919
- Id: ppid001 # Unique id, optional. Required if you would like to add scheduled task on this panel
2020
Title: Facade lighting # Panel title text
21+
EventTitle: House facade lighting # Verbose title text which shows in schedule editor (default value is the title value)
2122
PanelType: Switch # Controls a normal relay (For example lamp)
2223
DeviceType: Shelly
2324
DeviceIp: 192.168.1.101 # Ip address of shelly relay

glowdash/action.go

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func NewPanelAction() *PanelAction {
3333
idStr: "",
3434
panelType: Action,
3535
title: "",
36+
eventtitle: "",
3637
subPage: "",
3738
thumbImg: "",
3839
deviceType: "",

glowdash/glowdash.go

+12
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type PanelBase struct {
4545
idStr string
4646
panelType PanelTypes
4747
title string
48+
eventtitle string
4849
subPage string
4950
thumbImg string
5051
deviceType string
@@ -55,6 +56,7 @@ type PanelBase struct {
5556

5657
type PanelInterface interface {
5758
Title() string
59+
EventTitle() string
5860
PanelType() PanelTypes
5961
IdStr() string
6062
Sub() string
@@ -292,6 +294,16 @@ func readConfig(yamlfile string) bool {
292294
return false
293295
}
294296

297+
func PanelIdExists(id string) bool {
298+
pc := len(Panels)
299+
for i := 0; i < pc; i++ {
300+
if id == Panels[i].IdStr() {
301+
return true
302+
}
303+
}
304+
return false
305+
}
306+
295307
func panelUpdateRequestSSE(panelIds []string) {
296308
if DebugLevel > 2 {
297309
fmt.Printf("Send SSE message to refresh panelId: %s \n", strings.Join(panelIds, ","))

glowdash/group.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func NewPanelGroup() *PanelGroup {
2828
idStr: "",
2929
panelType: Group,
3030
title: "",
31+
eventtitle: "",
3132
subPage: "",
3233
thumbImg: "",
3334
deviceType: "",

glowdash/launch.go

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func NewPanelLaunch() *PanelLaunch {
2929
idStr: "",
3030
panelType: Launch,
3131
title: "",
32+
eventtitle: "",
3233
subPage: "",
3334
thumbImg: "",
3435
deviceType: "",

glowdash/panelbase.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ func (p PanelBase) Title() string {
3030
return p.title
3131
}
3232

33+
func (p PanelBase) EventTitle() string {
34+
return p.eventtitle
35+
}
36+
3337
func (p PanelBase) Sub() string {
3438
return p.subPage
3539
}
@@ -76,11 +80,20 @@ func (p *PanelBase) LoadBaseConfig(sy smartyaml.SmartYAML, indexInConfig int) {
7680
p.idStr = sy.GetStringByPathWithDefault(fmt.Sprintf("/GlowDash/Panels/[%d]/Id", indexInConfig), fmt.Sprintf("autogenId%d", indexInConfig+1))
7781
p.thumbImg = sy.GetStringByPathWithDefault(fmt.Sprintf("/GlowDash/Panels/[%d]/Thumbnail", indexInConfig), "")
7882
p.deviceType = sy.GetStringByPathWithDefault(fmt.Sprintf("/GlowDash/Panels/[%d]/DeviceType", indexInConfig), "Unknown")
79-
83+
p.eventtitle = sy.GetStringByPathWithDefault(fmt.Sprintf("/GlowDash/Panels/[%d]/EventTitle", indexInConfig), "")
84+
if p.eventtitle == "" {
85+
p.eventtitle = p.title
86+
}
8087
p.hide = false
8188
if sy.GetStringByPathWithDefault(fmt.Sprintf("/GlowDash/Panels/[%d]/Hide", indexInConfig), "") == "yes" {
8289
p.hide = true
8390
}
91+
92+
//Duplicated Id protection
93+
conf_id := p.idStr
94+
for runner := 1111 ; runner < 9999 && PanelIdExists(p.idStr) ; runner++ {
95+
p.idStr = fmt.Sprintf("%s%d",conf_id,runner)
96+
}
8497
}
8598

8699
func (p *PanelBase) LoadCustomConfig(sy smartyaml.SmartYAML, indexInConfig int) {

glowdash/scheduleedit.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func htmlStaticScheduleBlock(index int, cS int, s Schedule) string {
216216
title := "-"
217217
refPanel := GetPanelById(s.actionId)
218218
if refPanel != nil {
219-
title = refPanel.Title()
219+
title = refPanel.EventTitle()
220220
}
221221
html += "<div class=\"schedule-item-act\">"
222222
html += "<span class=\"schedule-item-act-id\">" + title + "</span>"
@@ -374,37 +374,37 @@ func htmlScheduleEditor(new bool, oneshotIfNew bool, s Schedule) string {
374374
}
375375

376376
if Panels[i].PanelType() == Switch {
377-
html += "<option value=\"switch:" + Panels[i].IdStr() + "\" " + selectedText + ">" + Panels[i].Title() + "</option>"
377+
html += "<option value=\"switch:" + Panels[i].IdStr() + "\" " + selectedText + ">" + Panels[i].EventTitle() + "</option>"
378378

379379
if current {
380380
subselOpts += "<option value=\"on\" " + IfTrue(s.actionParam == "on", "selected") + ">Switch On</option>"
381381
subselOpts += "<option value=\"off\" " + IfTrue(s.actionParam == "off", "selected") + ">Switch Off</option>"
382382
}
383383
}
384384
if Panels[i].PanelType() == Shading {
385-
html += "<option value=\"shading:" + Panels[i].IdStr() + "\" " + selectedText + ">" + Panels[i].Title() + "</option>"
385+
html += "<option value=\"shading:" + Panels[i].IdStr() + "\" " + selectedText + ">" + Panels[i].EventTitle() + "</option>"
386386

387387
if current {
388388
subselOpts += "<option value=\"open\" " + IfTrue(s.actionParam == "open", "selected") + ">Open</option>"
389389
subselOpts += "<option value=\"close\" " + IfTrue(s.actionParam == "close", "selected") + ">Close</option>"
390390
}
391391
}
392392
if Panels[i].PanelType() == Action {
393-
html += "<option value=\"action:" + Panels[i].IdStr() + "\" " + selectedText + ">" + Panels[i].Title() + "</option>"
393+
html += "<option value=\"action:" + Panels[i].IdStr() + "\" " + selectedText + ">" + Panels[i].EventTitle() + "</option>"
394394
if current {
395395
subselOpts += "<option value=\"run\" " + IfTrue(s.actionParam == "run", "selected") + ">Run</option>"
396396
}
397397
}
398398
if Panels[i].PanelType() == Script {
399-
html += "<option value=\"script:" + Panels[i].IdStr() + "\" " + selectedText + ">" + Panels[i].Title() + "</option>"
399+
html += "<option value=\"script:" + Panels[i].IdStr() + "\" " + selectedText + ">" + Panels[i].EventTitle() + "</option>"
400400

401401
if current {
402402
subselOpts += "<option value=\"start\" " + IfTrue(s.actionParam == "start", "selected") + ">Start</option>"
403403
subselOpts += "<option value=\"stop\" " + IfTrue(s.actionParam == "stop", "selected") + ">Stop</option>"
404404
}
405405
}
406406
if Panels[i].PanelType() == Thermostat {
407-
html += "<option value=\"therm:" + Panels[i].IdStr() + "\" " + selectedText + ">" + Panels[i].Title() + "</option>"
407+
html += "<option value=\"therm:" + Panels[i].IdStr() + "\" " + selectedText + ">" + Panels[i].EventTitle() + "</option>"
408408

409409
if current {
410410
apf, _ := strconv.ParseFloat(s.actionParam, 8)

glowdash/schedulepanel.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ func NewPanelScheduleShortcut() *PanelScheduleShortcut {
2727
return &PanelScheduleShortcut{
2828
PanelBase{
2929
idStr: "",
30-
panelType: Action,
30+
panelType: ScheduleShortcut,
3131
title: "",
32+
eventtitle: "",
3233
subPage: "",
3334
thumbImg: "",
3435
deviceType: "",

glowdash/script.go

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func NewPanelScript() *PanelScript {
2929
idStr: "",
3030
panelType: Script,
3131
title: "",
32+
eventtitle: "",
3233
subPage: "",
3334
thumbImg: "",
3435
deviceType: "",

glowdash/sensors.go

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func NewPanelSensors() *PanelSensors {
3838
idStr: "",
3939
panelType: Sensors,
4040
title: "",
41+
eventtitle: "",
4142
subPage: "",
4243
thumbImg: "",
4344
deviceType: "",

glowdash/shading.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func NewPanelShading() *PanelShading {
3131
idStr: "",
3232
panelType: Shading,
3333
title: "",
34+
eventtitle: "",
3435
subPage: "",
3536
thumbImg: "",
3637
deviceType: "",

glowdash/switch.go

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func NewPanelSwitch() *PanelSwitch {
2727
idStr: "",
2828
panelType: Switch,
2929
title: "",
30+
eventtitle: "",
3031
subPage: "",
3132
thumbImg: "",
3233
deviceType: "",

glowdash/thermostat.go

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func NewPanelThermostat() *PanelThermostat {
3737
idStr: "",
3838
panelType: Thermostat,
3939
title: "",
40+
eventtitle: "",
4041
subPage: "",
4142
thumbImg: "",
4243
deviceType: "",

0 commit comments

Comments
 (0)