BOSWatch 3
Python Script to receive and decode German BOS Information with rtl_fm and multimon-NG
 
Loading...
Searching...
No Matches
plugin.telegram.BoswatchPlugin Class Reference

Description of the Plugin. More...

Public Member Functions

 __init__ (self, config)
 Do not change anything here!
 
 onLoad (self)
 Called by import of the plugin.
 
 setup (self)
 Called before alarm.
 
 fms (self, bwPacket)
 Called on FMS alarm.
 
 pocsag (self, bwPacket)
 Called on POCSAG alarm.
 
 zvei (self, bwPacket)
 Called on ZVEI alarm.
 
 msg (self, bwPacket)
 Called on MSG packet.
 
 teardown (self)
 Called after alarm.
 
 onUnload (self)
 Called by destruction of the plugin.
 
- Public Member Functions inherited from plugin.pluginBase.PluginBase
 parseWildcards (self, msg)
 Return the message with parsed wildcards.
 

Data Fields

 sender
 
- Data Fields inherited from plugin.pluginBase.PluginBase
 config
 

Protected Member Functions

 _ensure_sender (self)
 
 _has_sender (self)
 
- Protected Member Functions inherited from plugin.pluginBase.PluginBase
 _cleanup (self)
 Cleanup routine calls onUnload() directly.
 
 _run (self, bwPacket)
 start an complete running turn of an plugin.
 
 _getStatistics (self)
 Returns statistical information's from last plugin run.
 

Additional Inherited Members

- Protected Attributes inherited from plugin.pluginBase.PluginBase
 _pluginName
 
 _bwPacket
 
 _sumTime
 
 _cumTime
 
 _setupTime
 
 _alarmTime
 
 _teardownTime
 
 _runCount
 
 _setupErrorCount
 
 _alarmErrorCount
 
 _teardownErrorCount
 
- Static Protected Attributes inherited from plugin.pluginBase.PluginBase
list _pluginsActive = []
 

Detailed Description

Description of the Plugin.

Constructor & Destructor Documentation

◆ __init__()

plugin.telegram.BoswatchPlugin.__init__ (   self,
  config 
)

Do not change anything here!

Reimplemented from plugin.pluginBase.PluginBase.

176 def __init__(self, config):
177 r"""!Do not change anything here!"""
178 super().__init__(__name__, config) # you can access the config class on 'self.config'
179

Member Function Documentation

◆ _ensure_sender()

plugin.telegram.BoswatchPlugin._ensure_sender (   self)
protected
 checking with hasattr if self.sender already exists
180 def _ensure_sender(self):
181 r""" checking with hasattr if self.sender already exists"""
182 if not hasattr(self, 'sender') or self.sender is None:
183 token = self.config.get("botToken")
184 ids = self.config.get("chatIds", default=[])
185
186 if token and ids:
187 self.sender = TelegramSender(
188 bot_token=token,
189 chat_ids=ids,
190 max_retries=self.config.get("max_retries"),
191 initial_delay=self.config.get("initial_delay"),
192 max_delay=self.config.get("max_delay"),
193 parse_mode=self.config.get("parse_mode")
194 )
195 logger.debug("TelegramSender initialized via Self-Healing")
196 else:
197 missing = []
198 if not token:
199 missing.append("botToken")
200 if not ids:
201 missing.append("chatIds")
202 logger.error(f"Telegram configuration incomplete! Missing: {', '.join(missing)}. Plugin will not send messages.")
203

◆ _has_sender()

plugin.telegram.BoswatchPlugin._has_sender (   self)
protected
Check if sender is available and properly initialized
204 def _has_sender(self):
205 r"""Check if sender is available and properly initialized"""
206 return hasattr(self, 'sender') and self.sender is not None
207

◆ onLoad()

plugin.telegram.BoswatchPlugin.onLoad (   self)

Called by import of the plugin.

Reimplemented from plugin.pluginBase.PluginBase.

208 def onLoad(self):
209 r"""!Called by import of the plugin"""
210 self._ensure_sender()
211 if not self._has_sender():
212 logger.warning("Telegram plugin loaded but not configured. Messages will be discarded.")
213 else:
214 startup = self.config.get("startup_message")
215 if startup and startup.strip():
216 self.sender.send_message(startup)
217

◆ setup()

plugin.telegram.BoswatchPlugin.setup (   self)

Called before alarm.

Reimplemented from plugin.pluginBase.PluginBase.

218 def setup(self):
219 r"""!Called before alarm"""
220 # ensure sender exists before alarms are processed
221 self._ensure_sender()
222

◆ fms()

plugin.telegram.BoswatchPlugin.fms (   self,
  bwPacket 
)

Called on FMS alarm.

Reimplemented from plugin.pluginBase.PluginBase.

223 def fms(self, bwPacket):
224 r"""!Called on FMS alarm"""
225 if self._has_sender():
226 msg = self.parseWildcards(self.config.get("message_fms", default="{FMS}"))
227 self.sender.send_message(msg)
228

◆ pocsag()

plugin.telegram.BoswatchPlugin.pocsag (   self,
  bwPacket 
)

Called on POCSAG alarm.

Reimplemented from plugin.pluginBase.PluginBase.

229 def pocsag(self, bwPacket):
230 r"""!Called on POCSAG alarm"""
231 if self._has_sender():
232 msg = self.parseWildcards(self.config.get("message_pocsag", default="{RIC}({SRIC})\n{MSG}"))
233 self.sender.send_message(msg)
234
235 if self.config.get("coordinates", default=False):
236 lat = bwPacket.get("lat")
237 lon = bwPacket.get("lon")
238 if lat is not None and lon is not None:
239 self.sender.send_location(lat, lon)
240

◆ zvei()

plugin.telegram.BoswatchPlugin.zvei (   self,
  bwPacket 
)

Called on ZVEI alarm.

Reimplemented from plugin.pluginBase.PluginBase.

241 def zvei(self, bwPacket):
242 r"""!Called on ZVEI alarm"""
243 if self._has_sender():
244 msg = self.parseWildcards(self.config.get("message_zvei", default="{TONE}"))
245 self.sender.send_message(msg)
246

◆ msg()

plugin.telegram.BoswatchPlugin.msg (   self,
  bwPacket 
)

Called on MSG packet.

Reimplemented from plugin.pluginBase.PluginBase.

247 def msg(self, bwPacket):
248 r"""!Called on MSG packet"""
249 if self._has_sender():
250 msg = self.parseWildcards(self.config.get("message_msg", default="{MSG}"))
251 self.sender.send_message(msg)
252

◆ teardown()

plugin.telegram.BoswatchPlugin.teardown (   self)

Called after alarm.

Reimplemented from plugin.pluginBase.PluginBase.

253 def teardown(self):
254 r"""!Called after alarm"""
255 pass
256

◆ onUnload()

plugin.telegram.BoswatchPlugin.onUnload (   self)

Called by destruction of the plugin.

Reimplemented from plugin.pluginBase.PluginBase.

257 def onUnload(self):
258 r"""!Called by destruction of the plugin"""
259 if self._has_sender():
260 self.sender.shutdown()
261 logger.info("Telegram plugin unloaded")

Field Documentation

◆ sender

plugin.telegram.BoswatchPlugin.sender