@@ -41,6 +41,9 @@ type MQTTAdapter struct {
4141 // Virtual device manager extracted from previous in-struct logic.
4242 vdevMgr * VdevManager
4343 mappers []MQTTMapper
44+
45+ // deviceSettings maps device ID to its configuration (for prohibited control etc)
46+ deviceSettings map [string ]EntityConfig
4447}
4548
4649// atomicBool (simple mutex-backed boolean) avoids importing sync/atomic for minimal usage.
@@ -65,8 +68,17 @@ func NewMQTTAdapter(cfg *Config, vdevMgr *VdevManager) (*MQTTAdapter, error) {
6568
6669 a := & MQTTAdapter {
6770
71+
6872 config : cfg ,
6973 vdevMgr : vdevMgr ,
74+ deviceSettings : make (map [string ]EntityConfig ),
75+ }
76+
77+ // Index device configurations for fast lookup
78+ for _ , room := range cfg .Rooms {
79+ for _ , entity := range room .Entities {
80+ a .deviceSettings [entity .ID ] = entity
81+ }
7082 }
7183
7284 // Build client options first.
@@ -167,6 +179,12 @@ func (a *MQTTAdapter) handleMapperMessage(mapper MQTTMapper, topic string, paylo
167179 log .Printf ("[mqtt] discovery error on topic %s: %v" , topic , derr )
168180 }
169181 if len (discovered ) > 0 {
182+ // Enrich discovered devices with config data
183+ for _ , d := range discovered {
184+ if cfg , ok := a .deviceSettings [d .ID ]; ok {
185+ d .ProhibitControl = cfg .ProhibitControl
186+ }
187+ }
170188 a .vdevMgr .AddDevices (discovered )
171189 }
172190
@@ -220,6 +238,11 @@ func (a *MQTTAdapter) ControlDevice(deviceID string, state any) error {
220238 return fmt .Errorf ("device %s is not a relay (type: %s)" , deviceID , targetDev .Type )
221239 }
222240
241+ // 2.5 Validation: ProhibitControl
242+ if targetDev .ProhibitControl {
243+ return fmt .Errorf ("control is prohibited for device %s" , deviceID )
244+ }
245+
223246 // 3. Validation: State must be ON or OFF
224247 stateStr , ok := state .(string )
225248 if ! ok {
0 commit comments