Skip to content

Commit

Permalink
New URL for Canada and adding additional tests for API results
Browse files Browse the repository at this point in the history
  • Loading branch information
gillesvs committed Mar 8, 2024
1 parent 0710a1d commit c12956f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 33 deletions.
2 changes: 1 addition & 1 deletion custom_components/librelink/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import aiohttp

from .const import (
API_TIME_OUT_SECONDS,
APPLICATION,
CONNECTION_URL,
LOGIN_URL,
PRODUCT,
VERSION_APP,
API_TIME_OUT_SECONDS,
)

_LOGGER = logging.getLogger(__name__)
Expand Down
5 changes: 3 additions & 2 deletions custom_components/librelink/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@

NAME = "LibreLink"
DOMAIN = "librelink"
VERSION = "1.2.1"
VERSION = "1.2.2"
ATTRIBUTION = "Data provided by https://libreview.com"
LOGIN_URL = "/llu/auth/login"
CONNECTION_URL = "/llu/connections"
COUNTRY = "Country"
COUNTRY_LIST = ["Global", "Russia"]
COUNTRY_LIST = ["Global", "Russia", "Canada"]
BASE_URL_LIST = {
"Global": "https://api.libreview.io",
"Russia": "https://api.libreview.ru",
"Canada": "https://api-ca.libreview.io",
}
PRODUCT = "llu.android"
VERSION_APP = "4.7"
Expand Down
7 changes: 6 additions & 1 deletion custom_components/librelink/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from datetime import timedelta
import logging

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
Expand All @@ -12,9 +13,11 @@
from .api import LibreLinkApiAuthenticationError, LibreLinkApiClient, LibreLinkApiError
from .const import DOMAIN, LOGGER, REFRESH_RATE_MIN

_LOGGER = logging.getLogger(__name__)


class LibreLinkDataUpdateCoordinator(DataUpdateCoordinator):
"""Class to manage fetching data from the API. single endpoint"""
"""Class to manage fetching data from the API. single endpoint."""

config_entry: ConfigEntry

Expand All @@ -39,6 +42,8 @@ async def _async_update_data(self):
try:
return await self.client.async_get_data()
except LibreLinkApiAuthenticationError as exception:
_LOGGER.debug("Exception: authentication error during coordinator update")
raise ConfigEntryAuthFailed(exception) from exception
except LibreLinkApiError as exception:
_LOGGER.debug("Exception: general API error during coordinator update")
raise UpdateFailed(exception) from exception
2 changes: 1 addition & 1 deletion custom_components/librelink/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"documentation": "https://github.com/gillesvs/librelink",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/gillesvs/librelink/issues",
"version": "1.2.1"
"version": "1.2.2"
}
34 changes: 6 additions & 28 deletions custom_components/librelink/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,14 @@ def __init__(
self.index = index
self.key = key

# res = None
# for i, patient in enumerate(self.coordinator.data):
# # for i in range(len(patients)):
# if patient.get("patientId") == "e4a78e05-0780-11ec-ad7d-0242ac110005":
# res = i
# break

# _LOGGER.debug(
# "index : %s",
# res,
# )

@property
def native_value(self):
"""Return the native value of the sensor."""

result = None

if self.patients:
# to avoid failing requests if there is no activated sensor for a patient.
if self.coordinator.data[self.index] is not None:
if self.key == "value":
if self.uom == MG_DL:
result = int(
Expand Down Expand Up @@ -163,16 +152,14 @@ def native_value(self):
]

elif self.key == "sensor":
if self.coordinator.data[self.index]["sensor"] != None:
if self.coordinator.data[self.index]["sensor"] is not None:
result = int(
(
time.time()
- (self.coordinator.data[self.index]["sensor"]["a"])
)
/ 86400
)
else:
result = "N/A"

elif self.key == "delay":
result = int(
Expand Down Expand Up @@ -222,24 +209,15 @@ def extra_state_attributes(self):
result = None
if self.coordinator.data[self.index]:
if self.key == "sensor":
if self.coordinator.data[self.index]["sensor"] != None:
if self.coordinator.data[self.index]["sensor"] is not None:
result = {
"Serial number": f"{self.coordinator.data[self.index]['sensor']['pt']} {self.coordinator.data[self.index]['sensor']['sn']}",
"Activation date": datetime.fromtimestamp(
(self.coordinator.data[self.index]["sensor"]["a"])
self.coordinator.data[self.index]["sensor"]["a"]
),
"patientId": self.coordinator.data[self.index]["patientId"],
"Patient": f"{(self.coordinator.data[self.index]['lastName']).upper()} {self.coordinator.data[self.index]['firstName']}",
}
else:
result = {
"Serial number": "N/A",
"Activation date": "N/A",
"patientId": self.coordinator.data[self.index]["patientId"],
"Patient": f"{(self.coordinator.data[self.index]['lastName']).upper()} {self.coordinator.data[self.index]['firstName']}",
}


}

return result
return result

0 comments on commit c12956f

Please sign in to comment.