modify drivers

This commit is contained in:
Adrian Zuercher
2025-07-29 12:37:04 +02:00
parent eabac1b11b
commit 4221815def
5 changed files with 62 additions and 25 deletions

View File

@@ -6,7 +6,7 @@ type Driver struct {
Buses map[string]*Bus `json:"buses"` // name of driver bus
}
func (d *Driver) AddBus(name string) *Bus {
func (d *Driver) AddNewBus(name string) *Bus {
if d.Buses == nil {
d.Buses = make(map[string]*Bus)
}
@@ -17,6 +17,24 @@ func (d *Driver) AddBus(name string) *Bus {
return d.Buses[name]
}
func (d *Driver) AddBuses(buses map[string]*Bus) {
if d.Buses == nil {
d.Buses = make(map[string]*Bus)
}
for key, newBus := range buses {
if currentBus, ok := d.Buses[key]; ok {
currentBus.AddAddress(newBus.Address...)
if newBus.Topic == nil {
continue
}
currentBus.AddSubscription(newBus.Topic.Subscribe...)
currentBus.AddPublish(newBus.Topic.Publish...)
continue
}
d.Buses[key] = newBus
}
}
func (d *Driver) GetBus(name string) *Bus {
if b, ok := d.Buses[name]; ok {
return b