Request component_nego only once for tapodevice (#576)

Optimizes the update cycle a bit, as it's doubtful the components change over time
This commit is contained in:
Teemu R 2023-12-10 00:32:30 +01:00 committed by GitHub
parent 35a452168a
commit a77af5fb3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,6 +24,7 @@ class TapoDevice(SmartDevice):
timeout: Optional[int] = None, timeout: Optional[int] = None,
) -> None: ) -> None:
super().__init__(host, port=port, credentials=credentials, timeout=timeout) super().__init__(host, port=port, credentials=credentials, timeout=timeout)
self._components: Optional[Dict[str, Any]] = None
self._state_information: Dict[str, Any] = {} self._state_information: Dict[str, Any] = {}
self._discovery_info: Optional[Dict[str, Any]] = None self._discovery_info: Optional[Dict[str, Any]] = None
self.protocol = SmartProtocol(host, credentials=credentials, timeout=timeout) self.protocol = SmartProtocol(host, credentials=credentials, timeout=timeout)
@ -33,7 +34,9 @@ class TapoDevice(SmartDevice):
if self.credentials is None or self.credentials.username is None: if self.credentials is None or self.credentials.username is None:
raise AuthenticationException("Tapo plug requires authentication.") raise AuthenticationException("Tapo plug requires authentication.")
self._components = await self.protocol.query("component_nego") if self._components is None:
self._components = await self.protocol.query("component_nego")
self._info = await self.protocol.query("get_device_info") self._info = await self.protocol.query("get_device_info")
self._usage = await self.protocol.query("get_device_usage") self._usage = await self.protocol.query("get_device_usage")
self._time = await self.protocol.query("get_device_time") self._time = await self.protocol.query("get_device_time")