Package: pyfireservicerota
Python: FireServiceRota / BrandweerRoosterBasic Python 3 API wrapper for FireServiceRota and BrandweerRooster for use with Home AssistantAboutThis package allows you to get notified about emergency incidents fromhttps://www.FireServiceRota.co.ukandhttps://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-realtimeGet user availability (duty)Set user incident response statusSeehttps://fireservicerota.co.ukandhttps://brandweerrooster.nlfor more details.NOTE: You need a subscription and login account to be able to use it.Installationpip3installpyfireservicerotaUsageInitialise module using user credentials to get token_info#!/usr/bin/env python3frompyfireservicerotaimportFireServiceRota,FireServiceRotaIncidents,ExpiredTokenError,InvalidTokenError,InvalidAuthErrorimportloggingimportsysimportjsonimporttimeimportthreading_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()exceptInvalidAuthError:token_info=Noneifnottoken_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 python3frompyfireservicerotaimportFireServiceRota,FireServiceRotaIncidents,ExpiredTokenError,InvalidTokenError,InvalidAuthErrorimportloggingimportsysimportjsonimporttime_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'))exceptExpiredTokenError:_LOGGER.debug("Tokens are expired, refreshing")try:token_info=api.refresh_tokens()exceptInvalidAuthError:_LOGGER.debug("Invalid refresh token, you need to re-login")exceptInvalidTokenError:_LOGGER.debug("Tokens are invalid")try:token_info=api.refresh_tokens()exceptInvalidAuthError:_LOGGER.debug("Invalid refresh token, you need to re-login")# Get incident response status for incident with id 123456incident_id=123456try:print(api.get_incident_response(incident_id))exceptExpiredTokenError:_LOGGER.debug("Tokens are expired, refreshing")try:token_info=api.refresh_tokens()exceptInvalidAuthError:_LOGGER.debug("Invalid refresh token, you need to re-login")exceptInvalidTokenError:_LOGGER.debug("Tokens are invalid")try:token_info=api.refresh_tokens()exceptInvalidAuthError:_LOGGER.debug("Invalid refresh token, you need to re-login")# Set incident response to acknowlegded (False = 'rejected')try:api.set_incident_response(id,True)exceptExpiredTokenError:_LOGGER.debug("Tokens are expired, refreshing")try:token_info=api.refresh_tokens()exceptInvalidAuthError:_LOGGER.debug("Invalid refresh token, you need to re-login")exceptInvalidTokenError:_LOGGER.debug("Tokens are invalid")try:token_info=api.refresh_tokens()exceptInvalidAuthError:_LOGGER.debug("Invalid refresh token, you need to re-login")# Connect to websocket channel for incidentswsurl=f"wss://www.brandweerrooster.nl/cable?access_token={token_info['access_token']}"classFireService():def__init__(self,url):self._data=Noneself.listener=Noneself.url=urlself.incidents_listener()defon_incident(self,data):_LOGGER.debug("INCIDENT:%s",data)self._data=datadefincidents_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)whileTrue:time.sleep(1)