From 18630074ba063b711f445e9cdf003e54cb6cd529 Mon Sep 17 00:00:00 2001 From: Ricardo Steijn Date: Mon, 9 Aug 2021 19:21:33 +0200 Subject: [PATCH] Add Final type to all constants. --- crownstone_sse/async_client.py | 2 +- crownstone_sse/const.py | 83 +++++++++++++++++----------------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/crownstone_sse/async_client.py b/crownstone_sse/async_client.py index 0ae8cf7..b52efab 100644 --- a/crownstone_sse/async_client.py +++ b/crownstone_sse/async_client.py @@ -93,7 +93,7 @@ def __init__( @property def is_available(self) -> bool: """Returns whether the client is currently running.""" - return self._state == AsyncClientState.RUNNING + return bool(self._state == AsyncClientState.RUNNING) async def __aenter__(self) -> CrownstoneSSEAsync: """Login & establish a new connection to the Crownstone SSE server.""" diff --git a/crownstone_sse/const.py b/crownstone_sse/const.py index 108c623..6bd051f 100644 --- a/crownstone_sse/const.py +++ b/crownstone_sse/const.py @@ -1,68 +1,69 @@ """Constants used by Crownstone SSE components.""" +from typing import Final # URLs -EVENT_BASE_URL = "https://events.crownstone.rocks/sse?accessToken=" -LOGIN_URL = "https://cloud.crownstone.rocks/api/users/login" +EVENT_BASE_URL: Final = "https://events.crownstone.rocks/sse?accessToken=" +LOGIN_URL: Final = "https://cloud.crownstone.rocks/api/users/login" # Headers -CONTENT_TYPE = "text/event-stream" -NO_CACHE = "no-cache" +CONTENT_TYPE: Final = "text/event-stream" +NO_CACHE: Final = "no-cache" # Connection parameters -RECONNECTION_TIME = 30 -CONNECTION_TIMEOUT = 35 +RECONNECTION_TIME: Final = 30 +CONNECTION_TIMEOUT: Final = 35 # SSE Ping event -EVENT_PING = "ping" +EVENT_PING: Final = "ping" # SSE System events -EVENT_SYSTEM = "system" -EVENT_SYSTEM_TOKEN_EXPIRED = "TOKEN_EXPIRED" -EVENT_SYSTEM_NO_ACCESS_TOKEN = "NO_ACCESS_TOKEN" -EVENT_SYSTEM_NO_CONNECTION = "NO_CONNECTION" -EVENT_SYSTEM_STREAM_START = "STREAM_START" -EVENT_SYSTEM_STREAM_CLOSED = "STREAM_CLOSED" +EVENT_SYSTEM: Final = "system" +EVENT_SYSTEM_TOKEN_EXPIRED: Final = "TOKEN_EXPIRED" +EVENT_SYSTEM_NO_ACCESS_TOKEN: Final = "NO_ACCESS_TOKEN" +EVENT_SYSTEM_NO_CONNECTION: Final = "NO_CONNECTION" +EVENT_SYSTEM_STREAM_START: Final = "STREAM_START" +EVENT_SYSTEM_STREAM_CLOSED: Final = "STREAM_CLOSED" # SSE dataChange events -EVENT_DATA_CHANGE = "dataChange" -EVENT_DATA_CHANGE_CROWNSTONE = "stones" -EVENT_DATA_CHANGE_SPHERES = "spheres" -EVENT_DATA_CHANGE_USERS = "users" -EVENT_DATA_CHANGE_LOCATIONS = "locations" +EVENT_DATA_CHANGE: Final = "dataChange" +EVENT_DATA_CHANGE_CROWNSTONE: Final = "stones" +EVENT_DATA_CHANGE_SPHERES: Final = "spheres" +EVENT_DATA_CHANGE_USERS: Final = "users" +EVENT_DATA_CHANGE_LOCATIONS: Final = "locations" # dataChange operations -OPERATION = "operation" -OPERATION_CREATE = "create" -OPERATION_DELETE = "delete" -OPERATION_UPDATE = "update" +OPERATION: Final = "operation" +OPERATION_CREATE: Final = "create" +OPERATION_DELETE: Final = "delete" +OPERATION_UPDATE: Final = "update" # SwitchState update events -EVENT_SWITCH_STATE_UPDATE = "switchStateUpdate" -EVENT_SWITCH_STATE_UPDATE_CROWNSTONE = "stone" +EVENT_SWITCH_STATE_UPDATE: Final = "switchStateUpdate" +EVENT_SWITCH_STATE_UPDATE_CROWNSTONE: Final = "stone" # SSE command events -EVENT_COMMAND = "command" -EVENT_COMMAND_SWITCH_MULTIPLE_CROWNSTONES = "multiSwitch" +EVENT_COMMAND: Final = "command" +EVENT_COMMAND_SWITCH_MULTIPLE_CROWNSTONES: Final = "multiSwitch" # SSE presence events -EVENT_PRESENCE = "presence" -EVENT_PRESENCE_ENTER_SPHERE = "enterSphere" -EVENT_PRESENCE_EXIT_SPHERE = "exitSphere" -EVENT_PRESENCE_ENTER_LOCATION = "enterLocation" -EVENT_PRESENCE_EXIT_LOCATION = "exitLocation" +EVENT_PRESENCE: Final = "presence" +EVENT_PRESENCE_ENTER_SPHERE: Final = "enterSphere" +EVENT_PRESENCE_EXIT_SPHERE: Final = "exitSphere" +EVENT_PRESENCE_ENTER_LOCATION: Final = "enterLocation" +EVENT_PRESENCE_EXIT_LOCATION: Final = "exitLocation" # SSE abilityChange events -EVENT_ABILITY_CHANGE = "abilityChange" -EVENT_ABILITY_CHANGE_DIMMING = "dimming" -EVENT_ABILITY_CHANGE_SWITCHCRAFT = "switchcraft" -EVENT_ABILITY_CHANGE_TAP_TO_TOGGLE = "tapToToggle" +EVENT_ABILITY_CHANGE: Final = "abilityChange" +EVENT_ABILITY_CHANGE_DIMMING: Final = "dimming" +EVENT_ABILITY_CHANGE_SWITCHCRAFT: Final = "switchcraft" +EVENT_ABILITY_CHANGE_TAP_TO_TOGGLE : Final= "tapToToggle" # errors -LOGIN_FAILED = "LOGIN_FAILED" -LOGIN_FAILED_EMAIL_NOT_VERIFIED = "LOGIN_FAILED_EMAIL_NOT_VERIFIED" +LOGIN_FAILED: Final = "LOGIN_FAILED" +LOGIN_FAILED_EMAIL_NOT_VERIFIED: Final = "LOGIN_FAILED_EMAIL_NOT_VERIFIED" # lists for iteration -system_events = [ +system_events: Final[list[str]] = [ EVENT_SYSTEM_TOKEN_EXPIRED, EVENT_SYSTEM_NO_ACCESS_TOKEN, EVENT_SYSTEM_NO_CONNECTION, @@ -70,21 +71,21 @@ EVENT_SYSTEM_STREAM_CLOSED, ] -presence_events = [ +presence_events: Final[list[str]] = [ EVENT_PRESENCE_ENTER_SPHERE, EVENT_PRESENCE_EXIT_SPHERE, EVENT_PRESENCE_ENTER_LOCATION, EVENT_PRESENCE_EXIT_LOCATION, ] -data_change_events = [ +data_change_events: Final[list[str]] = [ EVENT_DATA_CHANGE_USERS, EVENT_DATA_CHANGE_SPHERES, EVENT_DATA_CHANGE_CROWNSTONE, EVENT_DATA_CHANGE_LOCATIONS, ] -ability_change_events = [ +ability_change_events: Final[list[str]] = [ EVENT_ABILITY_CHANGE_DIMMING, EVENT_ABILITY_CHANGE_SWITCHCRAFT, EVENT_ABILITY_CHANGE_TAP_TO_TOGGLE,