diff --git a/custom_components/elektronny_gorod/api.py b/custom_components/elektronny_gorod/api.py index a9f9b59..56a4fff 100644 --- a/custom_components/elektronny_gorod/api.py +++ b/custom_components/elektronny_gorod/api.py @@ -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" @@ -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" diff --git a/custom_components/elektronny_gorod/config_flow.py b/custom_components/elektronny_gorod/config_flow.py index 86f9f94..3979ea7 100644 --- a/custom_components/elektronny_gorod/config_flow.py +++ b/custom_components/elektronny_gorod/config_flow.py @@ -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={