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

Retrieve and provide device id #6

Merged
merged 1 commit into from
Jun 28, 2024
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
2 changes: 2 additions & 0 deletions src/pyupway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class MyUpway:
_config: MyUpwayConfig

deviceId: str
isOnline: bool

def __init__(self, config: MyUpwayConfig) -> None:
Expand All @@ -23,6 +24,7 @@ def __init__(self, config: MyUpwayConfig) -> None:

self._service.login()

self.deviceId = self._service.deviceId
self.isOnline = self._service.isOnline

def login(self):
Expand Down
8 changes: 4 additions & 4 deletions src/pyupway/services/myuplinkservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class MyUplinkService:
_config: MyUpwayConfig
_session: requests.Session
_token: str
_device_id: str

deviceId: str
isOnline: bool

def __init__(self, config: MyUpwayConfig) -> None:
Expand All @@ -34,7 +34,7 @@ def login(self):

device_data = response_data['systems'][0]['devices'][0]

self._device_id = device_data['id']
self.deviceId = device_data['id']
self.isOnline = device_data['connectionState'] == "Connected"

def get_current_values(self, variables: List[Variable] | None = None, force_login: bool = False) -> List[VariableValue]:
Expand All @@ -50,12 +50,12 @@ def get_current_values(self, variables: List[Variable] | None = None, force_logi
"parameters": ','.join(str(variable.value) for variable in variables)
}

response = self._session.get(self._BASE_URL + '/v2/devices/' + self._device_id + '/points', params=params)
response = self._session.get(self._BASE_URL + '/v2/devices/' + self.deviceId + '/points', params=params)

if response.status_code == 401:
self._get_token()

response = self._session.get(self._BASE_URL + '/v2/devices/' + self._device_id + '/points', params=params)
response = self._session.get(self._BASE_URL + '/v2/devices/' + self.deviceId + '/points', params=params)

elif response.status_code != 200:
raise Exception(f"Failed to get values. API responded with status code {response.status_code}")
Expand Down
3 changes: 3 additions & 0 deletions src/pyupway/services/myupwayservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class MyUpwayService:
_config: MyUpwayConfig
_session: requests.Session

deviceId: str
isOnline: bool

def __init__(self, config: MyUpwayConfig) -> None:
Expand All @@ -37,6 +38,8 @@ def __init__(self, config: MyUpwayConfig) -> None:
# Set language to en to be able to get boolean values right
self._session.cookies.set("EmilLanguage", "en-GB", domain=self._DOMAIN)

self.deviceId = self._config.heatpump_id

self.login()

def login(self) -> None:
Expand Down