1 """Data for the D-Link Power Plug integration."""
3 from __future__
import annotations
5 from datetime
import datetime
9 from pyW215.pyW215
import SmartPlug
13 _LOGGER = logging.getLogger(__name__)
17 """Get the latest data from smart plug."""
19 def __init__(self, smartplug: SmartPlug) ->
None:
20 """Initialize the data object."""
22 self.
statestate: str |
None =
None
31 """Get the latest data from the smart plug."""
33 last_try_s = (dt_util.now() - self.
_last_tried_last_tried).total_seconds() / 60
34 retry_seconds =
min(self.
_n_tried_n_tried * 2, 10) - last_try_s
35 if self.
_n_tried_n_tried > 0
and retry_seconds > 0:
36 _LOGGER.warning(
"Waiting %s s to retry", retry_seconds)
44 except urllib.error.HTTPError:
45 _LOGGER.error(
"D-Link connection problem")
46 if _state ==
"unknown":
49 _LOGGER.warning(
"Failed to connect to D-Link switch")
None __init__(self, SmartPlug smartplug)