Skip to content

Commit

Permalink
Subdomain (#14)
Browse files Browse the repository at this point in the history
* Improve get sub domain

* style
  • Loading branch information
Danielhiversen authored Nov 16, 2018
1 parent f2272c9 commit 1b9fb17
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions mill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
MIN_TIME_BETWEEN_UPDATES = dt.timedelta(seconds=10)
REQUEST_TIMEOUT = '300'


_LOGGER = logging.getLogger(__name__)


class Mill:
"""Class to comunicate with the Mill api."""

# pylint: disable=too-many-instance-attributes, too-many-public-methods

def __init__(self, username, password,
Expand All @@ -34,6 +34,7 @@ def __init__(self, username, password,
if websession is None:
async def _create_session():
return aiohttp.ClientSession()

loop = asyncio.get_event_loop()
self.websession = loop.run_until_complete(_create_session())
else:
Expand Down Expand Up @@ -164,15 +165,15 @@ async def request(self, command, payload, retry=2):
return None
if not await self.connect():
return None
return await self.request(command, payload, retry-1)
return await self.request(command, payload, retry - 1)

if '"error":"device offline"' in result:
if retry < 1:
_LOGGER.error("Failed to send request, %s", result)
return None
_LOGGER.error("Failed to send request, %s. Retrying...", result)
await asyncio.sleep(3)
return await self.request(command, payload, retry-1)
return await self.request(command, payload, retry - 1)

if 'errorCode' in result:
_LOGGER.error("Failed to send request, %s", result)
Expand Down Expand Up @@ -325,7 +326,7 @@ async def heater_control(self, device_id, fan_status=None,
if power_status is None:
power_status = heater.power_status
operation = 0 if fan_status == heater.fan_status else 4
payload = {"subDomain": heater.sub_domain,
payload = {"subDomain": heater.sub_domain,
"deviceId": device_id,
"testStatus": 1,
"operation": operation,
Expand Down Expand Up @@ -438,7 +439,10 @@ async def set_heater_values(heater_data, heater):
heater.is_heating = heater_data.get('heatStatus',
heater_data.get('heaterFlag')
)
heater.sub_domain = heater_data.get('subDomain',
heater_data.get('subDomainId',
heater.sub_domain)
)
try:
heater.sub_domain = int(float(heater_data.get('subDomain',
heater_data.get('subDomainId',
heater.sub_domain)
)))
except ValueError:
pass

0 comments on commit 1b9fb17

Please sign in to comment.