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.

196 def __init__(self, config):
197 r"""!Do not change anything here!"""
198 super().__init__(__name__, config) # you can access the config class on 'self.config'
199

Member Function Documentation

◆ _ensure_sender()

plugin.telegram.BoswatchPlugin._ensure_sender (   self)
protected
 checking with hasattr if self.sender already exists
200 def _ensure_sender(self):
201 r""" checking with hasattr if self.sender already exists"""
202 if not hasattr(self, 'sender') or self.sender is None:
203 token = self.config.get("botToken")
204 ids = self.config.get("chatIds", default=[])
205
206 if token and ids:
207 self.sender = TelegramSender(
208 bot_token=token,
209 chat_ids=ids,
210 max_retries=self.config.get("max_retries"),
211 initial_delay=self.config.get("initial_delay"),
212 max_delay=self.config.get("max_delay"),
213 parse_mode=self.config.get("parse_mode")
214 )
215 logger.debug("TelegramSender initialized via Self-Healing")
216 else:
217 missing = []
218 if not token:
219 missing.append("botToken")
220 if not ids:
221 missing.append("chatIds")
222 logger.error(f"Telegram configuration incomplete! Missing: {', '.join(missing)}. Plugin will not send messages.")
223

◆ _has_sender()

plugin.telegram.BoswatchPlugin._has_sender (   self)
protected
Check if sender is available and properly initialized
224 def _has_sender(self):
225 r"""Check if sender is available and properly initialized"""
226 return hasattr(self, 'sender') and self.sender is not None
227

◆ onLoad()

plugin.telegram.BoswatchPlugin.onLoad (   self)

Called by import of the plugin.

Reimplemented from plugin.pluginBase.PluginBase.

228 def onLoad(self):
229 r"""!Called by import of the plugin"""
230 self._ensure_sender()
231 if not self._has_sender():
232 logger.warning("Telegram plugin loaded but not configured. Messages will be discarded.")
233 else:
234 startup = self.config.get("startup_message")
235 if startup and startup.strip():
236 self.sender.send_message(startup)
237

◆ setup()

plugin.telegram.BoswatchPlugin.setup (   self)

Called before alarm.

Reimplemented from plugin.pluginBase.PluginBase.

238 def setup(self):
239 r"""!Called before alarm"""
240 # ensure sender exists before alarms are processed
241 self._ensure_sender()
242

◆ fms()

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

Called on FMS alarm.

Reimplemented from plugin.pluginBase.PluginBase.

243 def fms(self, bwPacket):
244 r"""!Called on FMS alarm"""
245 if self._has_sender():
246 msg = self.parseWildcards(self.config.get("message_fms", default="{FMS}"))
247 self.sender.send_message(msg)
248

◆ pocsag()

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

Called on POCSAG alarm.

Reimplemented from plugin.pluginBase.PluginBase.

249 def pocsag(self, bwPacket):
250 r"""!Called on POCSAG alarm"""
251 if self._has_sender():
252 msg = self.parseWildcards(self.config.get("message_pocsag", default="{RIC}({SRIC})\n{MSG}"))
253 self.sender.send_message(msg)
254
255 if self.config.get("coordinates", default=False):
256 lat = bwPacket.get("lat")
257 lon = bwPacket.get("lon")
258 if lat is not None and lon is not None:
259 self.sender.send_location(lat, lon)
260

◆ zvei()

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

Called on ZVEI alarm.

Reimplemented from plugin.pluginBase.PluginBase.

261 def zvei(self, bwPacket):
262 r"""!Called on ZVEI alarm"""
263 if self._has_sender():
264 msg = self.parseWildcards(self.config.get("message_zvei", default="{TONE}"))
265 self.sender.send_message(msg)
266

◆ msg()

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

Called on MSG packet.

Reimplemented from plugin.pluginBase.PluginBase.

267 def msg(self, bwPacket):
268 r"""!Called on MSG packet"""
269 if self._has_sender():
270 msg = self.parseWildcards(self.config.get("message_msg", default="{MSG}"))
271 self.sender.send_message(msg)
272

◆ teardown()

plugin.telegram.BoswatchPlugin.teardown (   self)

Called after alarm.

Reimplemented from plugin.pluginBase.PluginBase.

273 def teardown(self):
274 r"""!Called after alarm"""
275 pass
276

◆ onUnload()

plugin.telegram.BoswatchPlugin.onUnload (   self)

Called by destruction of the plugin.

Reimplemented from plugin.pluginBase.PluginBase.

277 def onUnload(self):
278 r"""!Called by destruction of the plugin"""
279 if self._has_sender():
280 self.sender.shutdown()
281 logger.info("Telegram plugin unloaded")

Field Documentation

◆ sender

plugin.telegram.BoswatchPlugin.sender