Skip to content

Commit

Permalink
Add Final type to all constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
RicArch97 committed Aug 9, 2021
1 parent 0999721 commit 1863007
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 deletions.
2 changes: 1 addition & 1 deletion crownstone_sse/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
83 changes: 42 additions & 41 deletions crownstone_sse/const.py
Original file line number Diff line number Diff line change
@@ -1,90 +1,91 @@
"""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,
EVENT_SYSTEM_STREAM_START,
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,
Expand Down

0 comments on commit 1863007

Please sign in to comment.