Parse features only during updates (#527)

Every time emeter functions were called features had to be re-parsed. For power strips, thats a lot of re-parses. Only parse them when we update.
This commit is contained in:
J. Nick Koston
2023-10-07 09:18:47 -10:00
committed by GitHub
parent 0ec0826cc7
commit 9930311b54
3 changed files with 25 additions and 11 deletions

View File

@@ -37,6 +37,7 @@ async def test_invalid_connection(dev):
async def test_initial_update_emeter(dev, mocker):
"""Test that the initial update performs second query if emeter is available."""
dev._last_update = None
dev._features = set()
spy = mocker.spy(dev.protocol, "query")
await dev.update()
# Devices with small buffers may require 3 queries
@@ -48,6 +49,7 @@ async def test_initial_update_emeter(dev, mocker):
async def test_initial_update_no_emeter(dev, mocker):
"""Test that the initial update performs second query if emeter is available."""
dev._last_update = None
dev._features = set()
spy = mocker.spy(dev.protocol, "query")
await dev.update()
# 2 calls are necessary as some devices crash on unexpected modules