Skip to content

Commit fcb08f6

Browse files
committed
add writeonly writemode
1 parent b862d5b commit fcb08f6

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

classes/protocol_settings.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ class WriteMode(Enum):
137137
''' READ AND WRITE '''
138138

139139
#todo, write only
140+
WRITEONLY = 0x03
141+
''' WRITE ONLY'''
140142

141143
@classmethod
142144
def fromString(cls, name : str):
@@ -155,7 +157,8 @@ def fromString(cls, name : str):
155157
"R/W" : "WRITE",
156158
"RW" : "WRITE",
157159
"W" : "WRITE",
158-
"YES" : "WRITE"
160+
"YES" : "WRITE",
161+
"WO" : "WRITEONLY"
159162
}
160163

161164
if name in alias:
@@ -635,6 +638,9 @@ def calculate_registry_ranges(self, map : list[registry_map_entry], max_register
635638
if register.register >= start and register.register < end:
636639
if register.write_mode == WriteMode.READDISABLED: ##register is disabled; skip
637640
continue
641+
if register.write_mode == WriteMode.WRITEONLY: ##Write Only; skip
642+
continue
643+
638644
registers.append(register.register)
639645

640646
if registers: #not empty

classes/transports/mqtt.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def init_bridge(self, from_transport : transport_base):
194194
self.__write_topics = {}
195195
#subscribe to write topics
196196
for entry in from_transport.protocolSettings.get_registry_map(Registry_Type.HOLDING):
197-
if entry.write_mode == WriteMode.WRITE:
197+
if entry.write_mode == WriteMode.WRITE or entry.write_mode == WriteMode.WRITEONLY:
198198
#__write_topics
199199
topic : str = self.base_topic + "/write/" + entry.variable_name.lower().replace(' ', '_')
200200
self.__write_topics[topic] = entry
@@ -230,6 +230,7 @@ def mqtt_discovery(self, from_transport : transport_base):
230230
if item.write_mode == WriteMode.READDISABLED: #disabled
231231
continue
232232

233+
233234
clean_name = item.variable_name.lower().replace(' ', '_')
234235

235236
if False:
@@ -250,8 +251,8 @@ def mqtt_discovery(self, from_transport : transport_base):
250251
disc_payload['unique_id'] = "hotnoob_" + from_transport.device_serial_number + "_"+clean_name
251252

252253
writePrefix = ""
253-
if from_transport.write_enabled and item.write_mode == WriteMode.WRITE:
254-
writePrefix = "" #home assistant doesnt like write prefix
254+
if from_transport.write_enabled and ( item.write_mode == WriteMode.WRITE or item.write_mode == WriteMode.WRITEONLY ):
255+
writePrefix = "" #home assistant doesnt like write prefix
255256

256257
disc_payload['state_topic'] = self.base_topic + '/' +from_transport.device_identifier + writePrefix+ "/"+clean_name
257258

@@ -264,6 +265,10 @@ def mqtt_discovery(self, from_transport : transport_base):
264265
self.client.publish(discovery_topic,
265266
json.dumps(disc_payload),qos=1, retain=True)
266267

268+
#send WO message to indicate topic is write only
269+
if item.write_mode == WriteMode.WRITEONLY:
270+
self.client.publish(disc_payload['state_topic'], "WRITEONLY")
271+
267272
time.sleep(0.07) #slow down for better reliability
268273

269274
self.client.publish(disc_payload['availability_topic'],"online",qos=0, retain=True)

0 commit comments

Comments
 (0)