Raise an exception when trying to access data prior updating

This commit is contained in:
Teemu Rytilahti 2022-01-29 20:33:35 +01:00 committed by Teemu R
parent 3a7836cd33
commit bb013e75da

View File

@ -4,6 +4,8 @@ import logging
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
from ..exceptions import SmartDeviceException
if TYPE_CHECKING:
from kasa import SmartDevice
@ -44,6 +46,11 @@ class Module(ABC):
@property
def data(self):
"""Return the module specific raw data from the last update."""
if self._module not in self._device._last_update:
raise SmartDeviceException(
f"You need to call update() prior accessing module data for '{self._module}'"
)
return self._device._last_update[self._module]
@property