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

Make device info firmware version optional #812

Merged
merged 2 commits into from
Feb 1, 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
4 changes: 2 additions & 2 deletions pytradfri/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DeviceInfoResponse(BaseModel):
manufacturer: str = Field(alias=ATTR_DEVICE_MANUFACTURER)
model_number: str = Field(alias=ATTR_DEVICE_MODEL_NUMBER)
serial: str = Field(alias=ATTR_DEVICE_SERIAL)
firmware_version: str = Field(alias=ATTR_DEVICE_FIRMWARE_VERSION)
firmware_version: str | None = Field(alias=ATTR_DEVICE_FIRMWARE_VERSION)
power_source: int | None = Field(alias=ATTR_DEVICE_POWER_SOURCE)
battery_level: int | None = Field(alias=ATTR_DEVICE_BATTERY)

Expand Down Expand Up @@ -201,7 +201,7 @@ def serial(self) -> str:
return self.raw.serial

@property
def firmware_version(self) -> str:
def firmware_version(self) -> str | None:
"""Return current firmware version of device."""
return self.raw.firmware_version

Expand Down
20 changes: 20 additions & 0 deletions tests/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,23 @@
"9054": 0,
"9084": " 83 6f b7 c 7a f4 8a 14 4a 94 4a 94 41 e0 a2 4f",
}

DEVICE_WITHOUT_FIRMWARE_VERSION = {
"9001": "TRADFRI on/off switch 22",
"9003": 65639,
"9002": 1638114398,
"9020": 1706473768,
"9054": 0,
"9019": 1,
"3": {
"0": "IKEA of Sweden",
"1": "TRADFRI on/off switch",
"2": "",
"6": 3,
"7": 4549,
"8": 0,
"9": 50,
},
"5750": 0,
"15009": [{"9003": 0}],
}
9 changes: 9 additions & 0 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from .devices import (
BLIND,
DEVICE_WITHOUT_FIRMWARE_VERSION,
LIGHT_CWS,
LIGHT_PHILIPS,
LIGHT_W,
Expand Down Expand Up @@ -380,6 +381,14 @@ def test_device_info_properties(device):
assert info.power_source_str == "Internal Battery"


@pytest.mark.parametrize(
"device", [DEVICE_WITHOUT_FIRMWARE_VERSION], indirect=["device"]
)
def test_device_without_firmware_version(device):
"""Test device without firmware version."""
assert device.device_info.firmware_version is None


def test_set_name(device):
"""Test set name."""
command = device.set_name("New name")
Expand Down