Try not getting the same data over and over again...
This commit is contained in:
parent
1b5af38755
commit
6cd097fcfa
|
@ -13,15 +13,10 @@ class KumiSensors:
|
||||||
if not "://" in host:
|
if not "://" in host:
|
||||||
host = "http://" + host
|
host = "http://" + host
|
||||||
self.host = host
|
self.host = host
|
||||||
self.data = None
|
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
|
|
||||||
def fetch_data(self):
|
|
||||||
return json.load(urlopen(self.host))
|
|
||||||
|
|
||||||
async def get_data(self) -> dict:
|
async def get_data(self) -> dict:
|
||||||
self.data = self.data or await self.hass.async_add_executor_job(self.fetch_data)
|
return await self.hass.async_add_executor_job(json.load(urlopen(self.host)))
|
||||||
return self.data
|
|
||||||
|
|
||||||
async def connect(self) -> bool:
|
async def connect(self) -> bool:
|
||||||
"""Test if we can connect to the host."""
|
"""Test if we can connect to the host."""
|
||||||
|
|
Loading…
Reference in a new issue