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

Cache device class data #958

Merged
merged 10 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"generic": { "key": 2, "label": "Thermostat" },
"specific": { "key": 3, "label": "Thermostat General V2" },
"mandatorySupportedCCs": [],
"mandatoryControlCCs": []
"mandatoryControlledCCs": []
},
"isListening": true,
"isFrequentListening": false,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/cover_qubino_shutter_state.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"generic": { "key": 2, "label": "Multilevel Switch" },
"specific": { "key": 3, "label": "Motor Control Class C" },
"mandatorySupportedCCs": [],
"mandatoryControlCCs": []
"mandatoryControlledCCs": []
},
"isListening": true,
"isFrequentListening": false,
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/idl_101_lock_state.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"status": 4,
"ready": true,
"deviceClass": {
"basic": "Routing Slave",
"generic": "Entry Control",
"specific": "Secure Keypad Door Lock",
"basic": { "key": 4, "label": "Routing Slave" },
"generic": { "key": 2, "label": "Entry Control" },
"specific": { "key": 3, "label": "Secure Keypad Door Lock" },
"mandatorySupportedCCs": [
"Basic",
"Door Lock",
Expand All @@ -17,7 +17,7 @@
"Security",
"Version"
],
"mandatoryControlCCs": []
"mandatoryControlledCCs": []
},
"isListening": false,
"isFrequentListening": true,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/lock_schlage_be469_state.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"generic": { "key": 2, "label": "Entry Control" },
"specific": { "key": 3, "label": "Secure Keypad Door Lock" },
"mandatorySupportedCCs": [],
"mandatoryControlCCs": []
"mandatoryControlledCCs": []
},
"isListening": false,
"isFrequentListening": true,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/unparseable_json_string_value_state.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"generic": { "key": 2, "label": "Entry Control" },
"specific": { "key": 3, "label": "Secure Keypad Door Lock" },
"mandatorySupportedCCs": [],
"mandatoryControlCCs": []
"mandatoryControlledCCs": []
},
"isListening": false,
"isFrequentListening": true,
Expand Down
16 changes: 10 additions & 6 deletions zwave_js_server/model/device_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,33 @@ class DeviceClass:

def __init__(self, data: DeviceClassDataType) -> None:
"""Initialize."""
self.data = data
self._basic = DeviceClassItem(**data["basic"])
self._generic = DeviceClassItem(**data["generic"])
self._specific = DeviceClassItem(**data["specific"])
self._mandatory_supported_ccs: list[int] = data["mandatorySupportedCCs"]
self._mandatory_controlled_ccs: list[int] = data["mandatoryControlledCCs"]

@property
def basic(self) -> DeviceClassItem:
"""Return basic DeviceClass."""
return DeviceClassItem(**self.data["basic"])
return self._basic

@property
def generic(self) -> DeviceClassItem:
"""Return generic DeviceClass."""
return DeviceClassItem(**self.data["generic"])
return self._generic

@property
def specific(self) -> DeviceClassItem:
"""Return specific DeviceClass."""
return DeviceClassItem(**self.data["specific"])
return self._specific

@property
def mandatory_supported_ccs(self) -> list[int]:
"""Return list of mandatory Supported CC id's."""
return self.data["mandatorySupportedCCs"]
return self._mandatory_supported_ccs

@property
def mandatory_controlled_ccs(self) -> list[int]:
"""Return list of mandatory Controlled CC id's."""
return self.data["mandatoryControlledCCs"]
return self._mandatory_controlled_ccs
9 changes: 6 additions & 3 deletions zwave_js_server/model/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(
self.node = node
self.data: EndpointDataType = data
self.values: dict[str, ConfigurationValue | Value] = {}
self._device_class: None | DeviceClass = None
raman325 marked this conversation as resolved.
Show resolved Hide resolved
self.update(data, values)

def __repr__(self) -> str:
Expand Down Expand Up @@ -90,9 +91,7 @@ def index(self) -> int:
@property
def device_class(self) -> DeviceClass | None:
"""Return the device_class."""
if (device_class := self.data.get("deviceClass")) is None:
return None
return DeviceClass(device_class)
return self._device_class

@property
def installer_icon(self) -> int | None:
Expand All @@ -119,6 +118,10 @@ def update(
) -> None:
"""Update the endpoint data."""
self.data = data
if (device_class := self.data.get("deviceClass")) is None:
self._device_class = None
else:
self._device_class = DeviceClass(device_class)

# Remove stale values
self.values = {
Expand Down
10 changes: 7 additions & 3 deletions zwave_js_server/model/node/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def __init__(self, client: Client, data: NodeDataType) -> None:
client, data.get("statistics", DEFAULT_NODE_STATISTICS)
)
self._firmware_update_progress: NodeFirmwareUpdateProgress | None = None
self._device_class: None | DeviceClass = None
raman325 marked this conversation as resolved.
Show resolved Hide resolved
self.values: dict[str, ConfigurationValue | Value] = {}
self.endpoints: dict[int, Endpoint] = {}
self.status_event = asyncio.Event()
Expand Down Expand Up @@ -149,9 +150,7 @@ def index(self) -> int:
@property
def device_class(self) -> DeviceClass | None:
"""Return the device_class."""
if (device_class := self.data.get("deviceClass")) is None:
return None
return DeviceClass(device_class)
return self._device_class

@property
def installer_icon(self) -> int | None:
Expand Down Expand Up @@ -377,6 +376,11 @@ def update(self, data: NodeDataType) -> None:
"""Update the internal state data."""
self.data = copy.deepcopy(data)
self._device_config = DeviceConfig(self.data.get("deviceConfig", {}))
if (device_class := self.data.get("deviceClass")) is None:
self._device_class = None
else:
self._device_class = DeviceClass(device_class)

self._statistics = NodeStatistics(
self.client, self.data.get("statistics", DEFAULT_NODE_STATISTICS)
)
Expand Down
Loading