Skip to content

Commit ac65380

Browse files
committed
refactor: optimize device lookup in mock data by caching parsed device objects
1 parent 6b1f9b3 commit ac65380

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

tests/mock_data.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,13 @@
154154
_PRODUCTS_BY_ID: dict[str, HomeDataProduct] = {
155155
p.id: p for p in (HomeDataProduct.from_dict(v) for v in PRODUCTS.values())
156156
}
157+
_DEVICES_BY_FILENAME: dict[str, HomeDataDevice] = {
158+
filename: HomeDataDevice.from_dict(device_data) for filename, device_data in DEVICES.items()
159+
}
157160
DEVICE_PRODUCT_PAIRS: dict[str, tuple[HomeDataDevice, HomeDataProduct]] = {
158-
filename: (HomeDataDevice.from_dict(raw), product)
159-
for filename, raw in DEVICES.items()
160-
if (product := _PRODUCTS_BY_ID.get(HomeDataDevice.from_dict(raw).product_id)) is not None
161+
filename: (device, product)
162+
for filename, device in _DEVICES_BY_FILENAME.items()
163+
if (product := _PRODUCTS_BY_ID.get(device.product_id)) is not None
161164
}
162165

163166

0 commit comments

Comments
 (0)