Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration name change #3

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions custom_components/elektronny_gorod/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ async def verify_sms_code(self, contract:object, code:str) -> dict:
)
return await self.request(api_url, data, method="POST")

async def update_access_token(self, access_token) -> None:
self.access_token = access_token

async def query_profile(self) -> dict:
"""Query the profile data for subscriber."""
api_url = f"{self.base_url}/rest/v1/subscribers/profiles"

profile = await self.request(api_url)
return profile["data"] if profile else {}

async def query_places(self) -> list:
"""Query the list of places for subscriber."""
api_url = f"{self.base_url}/rest/v1/subscriberplaces"

places = await self.request(api_url)
return places["data"] if places else []

async def query_cameras(self) -> list:
"""Query the list of cameras for access token."""
api_url = f"{self.base_url}/rest/v1/forpost/cameras"
Expand All @@ -85,13 +102,6 @@ async def query_camera_snapshot(self, id, width, height) -> bytes:
api_url = f"{self.base_url}/rest/v1/forpost/cameras/{id}/snapshots?width={width}&height={height}"
return await self.request(api_url, binary=True)

async def query_places(self) -> list:
"""Query the list of places for subscriber."""
api_url = f"{self.base_url}/rest/v1/subscriberplaces"

places = await self.request(api_url)
return places["data"] if places else []

async def open_lock(self, place_id, access_control_id, entrance_id) -> list:
"""Query the list of places for subscriber."""
api_url = f"{self.base_url}/rest/v1/places/{place_id}/accesscontrols/{access_control_id}/entrances/{entrance_id}/actions"
Expand Down
5 changes: 4 additions & 1 deletion custom_components/elektronny_gorod/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ async def async_step_sms(
# Verify the SMS code
if auth:
# If code is verified, create config entry
name = f"Electronic City ({self.contract})"
await self.api.update_access_token(auth["accessToken"])
profile = await self.api.query_profile()
subscriber = profile["subscriber"]
name = f"{subscriber['name']} (Account ID: {subscriber['accountId']})"
return self.async_create_entry(
title=name,
data={
Expand Down