Skip to content

Commit 7f4f93c

Browse files
committed
v1.9beta1: requests based HTTP communication, code refactor
1 parent e14e69d commit 7f4f93c

File tree

6 files changed

+206
-209
lines changed

6 files changed

+206
-209
lines changed

myio/__init__.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
99
from homeassistant.util import slugify
1010

11-
from .const import CLIMATE, CONF_REFRESH_TIME, COVER, DOMAIN, LIGHT, SENSOR, DEFAULT_REFRESH_TIME
11+
from .const import CLIMATE, CONF_REFRESH_TIME, COVER, DOMAIN, LIGHT, SENSOR
1212
from .comm.comms_thread import CommsThread2
1313

1414
_LOGGER = logging.getLogger(__name__)
@@ -42,11 +42,7 @@ async def async_setup_entry(hass, config_entry):
4242
hass.states.async_set(f"{_server_name}.state", "Offline")
4343
hass.states.async_set(f"{_server_name}.first_contact", "True")
4444

45-
_refresh_timer = config_entry.options.get(CONF_REFRESH_TIME, DEFAULT_REFRESH_TIME)
46-
47-
_LOGGER.debug("MYIO Config:")
48-
for key in config_entry.options:
49-
_LOGGER.debug(f"{key}: {config_entry.options(key)}")
45+
_refresh_timer = config_entry.options.get(CONF_REFRESH_TIME, 6)
5046

5147
def server_data():
5248
"""Return the server data dictionary database."""
@@ -69,14 +65,14 @@ async def async_update_data():
6965
"""Fetch data from API endpoint."""
7066

7167
was_offline = False
72-
_timeout = 4
68+
_timeout = 30
7369
_comms_thread_timeout = False
7470
_temp_server_state = hass.states.get(f"{_server_name}.state").state
7571

7672
if _temp_server_state == "Offline":
7773
hass.states.async_set(f"{_server_name}.available", False)
7874
was_offline = True
79-
_timeout = 20
75+
_timeout = 30
8076

8177
# Pull fresh data from server.
8278
try:
@@ -88,7 +84,8 @@ async def async_update_data():
8884
server_data=server_data(),
8985
server_status=_temp_server_state,
9086
config_entry=config_entry,
91-
_post=None
87+
_post=None,
88+
hass = hass
9289
),
9390
timeout=_timeout,
9491
)

myio/climate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
_LOGGER = logging.getLogger(__name__)
2424
SUPPORT_FLAGS = 0
25-
SCAN_INTERVAL = timedelta(seconds=5)
25+
SCAN_INTERVAL = timedelta(seconds=30)
2626
COMMS_THREAD = CommsThread2()
2727

2828

@@ -280,6 +280,7 @@ async def send_post(self, post):
280280
server_status=self.server_status(),
281281
config_entry=self._config_entry,
282282
_post=post,
283+
hass = self.hass
283284
)
284285
self.hass.states.async_set(f"{self._server_name}.state", self._server_status)
285286
return True

0 commit comments

Comments
 (0)