Skip to content

Commit

Permalink
Merge pull request #46 from robberwick/defaults
Browse files Browse the repository at this point in the history
Add defaults for pydantic fields
  • Loading branch information
robberwick authored Dec 4, 2024
2 parents 240edb4 + a25bb2b commit 5fcbe51
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 89 deletions.
8 changes: 4 additions & 4 deletions src/pylibrelinkup/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class AlarmRules(BaseModel):
f: F
l: L
nd: Nd
p: int
r: int
p: int = Field(default=0)
r: int = Field(default=0)
std: Std


Expand All @@ -34,5 +34,5 @@ class FixedLowAlarmValues(BaseModel):
from_attributes=True,
)

mgdl: int
mmoll: float
mgdl: int = Field(default=0)
mmoll: float = Field(default=0.0)
24 changes: 12 additions & 12 deletions src/pylibrelinkup/models/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ class Connection(BaseModel):

id: UUID
patient_id: UUID
country: str
status: int
first_name: str
last_name: str
target_low: int
target_high: int
uom: int
country: str = Field(default="")
status: int = Field(default=0)
first_name: str = Field(default="")
last_name: str = Field(default="")
target_low: int = Field(default=0)
target_high: int = Field(default=0)
uom: int = Field(default=0)
sensor: Sensor
alarm_rules: AlarmRules
glucose_measurement: GlucoseMeasurement
glucose_item: GlucoseMeasurement
glucose_alarm: None
patient_device: PatientDevice
created: int
created: int = Field(default=0)


class Data(BaseModel):
Expand Down Expand Up @@ -64,9 +64,9 @@ class Ticket(BaseModel):
from_attributes=True,
)

token: str
expires: int
duration: int
token: str = Field(default="")
expires: int = Field(default=0)
duration: int = Field(default=0)


class GraphResponse(BaseModel):
Expand All @@ -79,7 +79,7 @@ class GraphResponse(BaseModel):
from_attributes=True,
)

status: int
status: int = Field(default=0)
data: Data
ticket: Ticket

Expand Down
49 changes: 26 additions & 23 deletions src/pylibrelinkup/models/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ class GlucoseMeasurement(BaseModel):

factory_timestamp: datetime = Field(None)
timestamp: datetime = Field(None)
type: int
value_in_mg_per_dl: float
measurement_color: int
glucose_units: int
value: float
type: int = Field(default=0)
value_in_mg_per_dl: float = Field(default=0.0)
measurement_color: int = Field(default=0)
glucose_units: int = Field(default=0)
value: float = Field(default=0.0)
is_high: bool = Field(alias="isHigh")
is_low: bool = Field(alias="isLow")

Expand Down Expand Up @@ -104,11 +104,11 @@ class F(BaseModel):
from_attributes=True,
)

th: int
thmm: float
d: int
tl: int
tlmm: float
th: int = Field(default=0)
thmm: float = Field(default=0.0)
d: int = Field(default=0)
tl: int = Field(default=0)
tlmm: float = Field(default=0.0)


class L(BaseModel):
Expand All @@ -118,11 +118,12 @@ class L(BaseModel):
from_attributes=True,
)

th: int
thmm: float
d: int
tl: int
tlmm: float

th: int = Field(default=0)
thmm: float = Field(default=0.0)
d: int = Field(default=0)
tl: int = Field(default=0)
tlmm: float = Field(default=0.0)


class H(BaseModel):
Expand All @@ -132,10 +133,11 @@ class H(BaseModel):
from_attributes=True,
)

th: int
thmm: float
d: int
f: float

th: int = Field(default=0)
thmm: float = Field(default=0.0)
d: int = Field(default=0)
f: float = Field(default=0.0)


class Nd(BaseModel):
Expand All @@ -145,9 +147,10 @@ class Nd(BaseModel):
from_attributes=True,
)

i: int
r: int
l: int

i: int = Field(default=0)
r: int = Field(default=0)
l: int = Field(default=0)


class Std(BaseModel):
Expand All @@ -157,4 +160,4 @@ class Std(BaseModel):
model_config = ConfigDict(
from_attributes=True,
)
sd: bool | None = None
sd: bool | None = Field(default=None)
35 changes: 19 additions & 16 deletions src/pylibrelinkup/models/hardware.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel

from .config import FixedLowAlarmValues
Expand All @@ -16,11 +16,12 @@ class Sensor(BaseModel):
from_attributes=True,
)

device_id: str
sn: str
a: int
w: int
pt: int

device_id: str = Field(default="")
sn: str = Field(default="")
a: int = Field(default=0)
w: int = Field(default=0)
pt: int = Field(default=0)


class PatientDevice(BaseModel):
Expand All @@ -33,14 +34,15 @@ class PatientDevice(BaseModel):
from_attributes=True,
)

did: str
dtid: int
v: str
ll: int
hl: int
u: int
fixed_low_alarm_values: FixedLowAlarmValues
alarms: bool

did: str = Field(default="")
dtid: int = Field(default=0)
v: str = Field(default="")
ll: int = Field(default=0)
hl: int = Field(default=0)
u: int = Field(default=0)
fixed_low_alarm_values: FixedLowAlarmValues
alarms: bool = Field(default=False)


class ActiveSensor(BaseModel):
Expand All @@ -53,5 +55,6 @@ class ActiveSensor(BaseModel):
from_attributes=True,
)

sensor: Sensor
device: PatientDevice

sensor: Sensor
device: PatientDevice
66 changes: 33 additions & 33 deletions src/pylibrelinkup/models/login.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List

from pydantic import BaseModel
from pydantic import BaseModel, Field

__all__ = [
"Llu",
Expand All @@ -22,39 +22,39 @@


class Llu(BaseModel):
policyAccept: int
touAccept: int
policyAccept: int = Field(default=0)
touAccept: int = Field(default=0)


class Consents(BaseModel):
llu: Llu


class SystemMessages(BaseModel):
firstUsePhoenix: int
firstUsePhoenixReportsDataMerged: int
lluGettingStartedBanner: int
lluNewFeatureModal: int
lluOnboarding: int
lvWebPostRelease: str
firstUsePhoenix: int = Field(default=0)
firstUsePhoenixReportsDataMerged: int = Field(default=0)
lluGettingStartedBanner: int = Field(default=0)
lluNewFeatureModal: int = Field(default=0)
lluOnboarding: int = Field(default=0)
lvWebPostRelease: str = Field(default="")


class System(BaseModel):
messages: SystemMessages


class User(BaseModel):
id: str
firstName: str
lastName: str
email: str
country: str
uiLanguage: str
communicationLanguage: str
accountType: str
uom: str
dateFormat: str
timeFormat: str
id: str = Field(default="")
firstName: str = Field(default="")
lastName: str = Field(default="")
email: str = Field(default="")
country: str = Field(default="")
uiLanguage: str = Field(default="")
communicationLanguage: str = Field(default="")
accountType: str = Field(default="")
uom: str = Field(default="")
dateFormat: str = Field(default="")
timeFormat: str = Field(default="")
emailDay: List[int]
system: System
details: dict
Expand All @@ -68,17 +68,17 @@ class User(BaseModel):


class Notifications(BaseModel):
unresolved: int
unresolved: int = Field(default=0)


class DataMessages(BaseModel):
unread: int
unread: int = Field(default=0)


class AuthTicket(BaseModel):
token: str
expires: int
duration: int
token: str = Field(default="")
expires: int = Field(default=0)
duration: int = Field(default=0)


class Data(BaseModel):
Expand All @@ -90,29 +90,29 @@ class Data(BaseModel):


class LoginResponse(BaseModel):
status: int
status: int = Field(default=0)
data: Data


class ErrorMessage(BaseModel):
message: str
message: str = Field(default="")


class LoginResponseUnauthenticated(BaseModel):
status: int
status: int = Field(default=0)
error: ErrorMessage


class LoginRedirectData(BaseModel):
redirect: bool
region: str
redirect: bool = Field(default=False)
region: str = Field(default="")


class LoginRedirectResponse(BaseModel):
status: int
status: int = Field(default=0)
data: LoginRedirectData


class LoginArgs(BaseModel):
email: str = ""
password: str = ""
email: str = Field(default="")
password: str = Field(default="")
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def graph_response_no_alarm_rules_c_json(get_response_json):
return get_response_json("graph_response_no_alarm_rules_c.json")


@pytest.fixture
def graph_response_no_u_json(get_response_json):
return get_response_json("graph_response_no_u.json")


@dataclass
class PyLibreLinkUpClientFixture:
client: PyLibreLinkUp
Expand Down
Loading

0 comments on commit 5fcbe51

Please sign in to comment.