Try not getting the same data over and over again...

This commit is contained in:
Kumi 2021-05-22 20:58:57 +02:00
parent 1b5af38755
commit 6cd097fcfa

View file

@ -13,15 +13,10 @@ class KumiSensors:
if not "://" in host:
host = "http://" + host
self.host = host
self.data = None
self.hass = hass
def fetch_data(self):
return json.load(urlopen(self.host))
async def get_data(self) -> dict:
self.data = self.data or await self.hass.async_add_executor_job(self.fetch_data)
return self.data
return await self.hass.async_add_executor_job(json.load(urlopen(self.host)))
async def connect(self) -> bool:
"""Test if we can connect to the host."""