Skip to main content

Python: FireServiceRota / BrandweerRooster

Basic Python 3 API wrapper for FireServiceRota and BrandweerRooster for use with Home Assistant

About

This package allows you to get notified about emergency incidents from https://www.FireServiceRota.co.uk and https://www.BrandweerRooster.nl. Those are services used by firefighters.

It currently provides the following limited functionality:

  • Connect to the websocket to get incident details in near-realtime
  • Get user availability (duty)
  • Set user incident response status

See https://fireservicerota.co.uk and https://brandweerrooster.nl for more details.

NOTE: You need a subscription and login account to be able to use it.

Installation

pip3 install pyfireservicerota

Usage

Initialise module using user credentials to get token_info

#!/usr/bin/env python3

from pyfireservicerota import FireServiceRota, FireServiceRotaIncidents, ExpiredTokenError, InvalidTokenError, InvalidAuthError
import logging
import sys
import json
import time
import threading

_LOGGER = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

token_info = {}

api = FireServiceRota(
      base_url="www.brandweerrooster.nl",
      username="your@email.address",
      password="yourpassword",
)

try:
    token_info = api.request_tokens()
except InvalidAuthError:
    token_info = None

if not token_info:
    _LOGGER.error("Failed to get access tokens")

NOTE: You don't need to store user credentials, at first authentication just the token_info dictionary is enough use api.refresh_tokens to refresh it.

Initialise module with stored token_info

#!/usr/bin/env python3

from pyfireservicerota import FireServiceRota, FireServiceRotaIncidents, ExpiredTokenError, InvalidTokenError, InvalidAuthError
import logging
import sys
import json
import time


_LOGGER = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

token_info = {}

api = FireServiceRota(
      base_url = "www.brandweerrooster.nl",
      token_info = token_info
    )

# Get user availability (duty)
try:
   print(api.get_availability('Europe/Amsterdam'))
except ExpiredTokenError:
   _LOGGER.debug("Tokens are expired, refreshing")
   try:
       token_info = api.refresh_tokens()
   except InvalidAuthError:
       _LOGGER.debug("Invalid refresh token, you need to re-login")
except InvalidTokenError:
   _LOGGER.debug("Tokens are invalid")
   try:
       token_info = api.refresh_tokens()
   except InvalidAuthError:
       _LOGGER.debug("Invalid refresh token, you need to re-login")

# Get incident response status for incident with id 123456

incident_id = 123456

try:
   print(api.get_incident_response(incident_id))
except ExpiredTokenError:
   _LOGGER.debug("Tokens are expired, refreshing")
   try:
       token_info = api.refresh_tokens()
   except InvalidAuthError:
       _LOGGER.debug("Invalid refresh token, you need to re-login")
except InvalidTokenError:
   _LOGGER.debug("Tokens are invalid")
   try:
       token_info = api.refresh_tokens()
   except InvalidAuthError:
       _LOGGER.debug("Invalid refresh token, you need to re-login")


# Set incident response to acknowlegded (False = 'rejected')
try:
   api.set_incident_response(id, True)
except ExpiredTokenError:
   _LOGGER.debug("Tokens are expired, refreshing")
   try:
       token_info = api.refresh_tokens()
   except InvalidAuthError:
       _LOGGER.debug("Invalid refresh token, you need to re-login")
except InvalidTokenError:
   _LOGGER.debug("Tokens are invalid")
   try:
       token_info = api.refresh_tokens()
   except InvalidAuthError:
       _LOGGER.debug("Invalid refresh token, you need to re-login")


# Connect to websocket channel for incidents
wsurl = f"wss://www.brandweerrooster.nl/cable?access_token={token_info['access_token']}"

class FireService():

    def __init__(self, url):

        self._data = None
        self.listener = None
        self.url = url
        self.incidents_listener()

    def on_incident(self, data):
        _LOGGER.debug("INCIDENT: %s", data)
        self._data = data

    def incidents_listener(self):
        """Spawn a new Listener and links it to self.on_incident."""

        self.listener = FireServiceRotaIncidents(on_incident=self.on_incident)
        _LOGGER.debug("Starting incidents listener")
        self.listener.start(url=self.url)


ws = FireService(wsurl)

while True:
    time.sleep(1)

Metadata

Release files for pyfireservicerota 0.0.44

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfireservicerota 0.0.44
File Size Uploaded Provenance Actions
pyfireservicerota-0.0.44.tar.gz 6.0 kB Without provenance Details for pyfireservicerota-0.0.44.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyfireservicerota 0.0.44
File Interpreter ABI Platform Actions
pyfireservicerota-0.0.44-py3-none-any.whl Python 3 none any Details for pyfireservicerota-0.0.44-py3-none-any.whl

Total release size: 12.6 kB

Release files / pyfireservicerota-0.0.44.tar.gz

Download URL pyfireservicerota-0.0.44.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3a49c65f8c4ff801d746e862cdb7935407e2397d2e446cc0972ec5275be8a432
BLAKE2b-256 checksum
How to use checksums
f5a35cbe4271bbc1f13a7231040c2e1cb65d2c865089c5cb653184a0809c951f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release files / pyfireservicerota-0.0.44-py3-none-any.whl

Download URL pyfireservicerota-0.0.44-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ba78b1f85271c38ca97b9d0dfb47545ae1d1a854c07e1a4b6aa8ad1878a2656
BLAKE2b-256 checksum
How to use checksums
2fced1973d3a3c0709d464af682f08107d532cd28f293c7f188c0e0d12ee53bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Security for pyfireservicerota 0.0.44

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.44 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page