Guard emeter accesses to avoid keyerrors (#304)

Raise an exception to inform the caller that update() is needed
This commit is contained in:
Teemu R
2022-02-02 19:31:11 +01:00
committed by GitHub
parent 9ea83388ac
commit 700f3859c2

View File

@@ -219,6 +219,8 @@ class SmartDevice:
"""Raise an exception if there is no emeter."""
if not self.has_emeter:
raise SmartDeviceException("Device has no emeter")
if self.emeter_type not in self._last_update:
raise SmartDeviceException("update() required prior accessing emeter")
async def _query_helper(
self, target: str, cmd: str, arg: Optional[Dict] = None, child_ids=None