forked from Danielhiversen/pyMillLocal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Daniel Hjelseth Høyer <[email protected]>
- Loading branch information
1 parent
e78e938
commit 2d79242
Showing
1 changed file
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,73 @@ | ||
"""Init""" | ||
"""Local support for Mill wifi-enabled home heaters.""" | ||
import asyncio | ||
import logging | ||
|
||
import async_timeout | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class Mill: | ||
"""Mill data handler.""" | ||
|
||
def __init__(self, device_ip, websession, timeout=15): | ||
"""Init Mill data handler.""" | ||
self.device_ip = device_ip | ||
self.websession = websession | ||
self._url = "http:https://" + device_ip + "/" | ||
self._timeout = timeout | ||
|
||
async def set_target_temperature(self, target_temperature): | ||
"""Set target temperature.""" | ||
payload = { | ||
"type": "Normal", | ||
"value": target_temperature, | ||
} | ||
with async_timeout.timeout(self._timeout): | ||
async with self.websession.post( | ||
f"{self._url}/control-status", | ||
payload=payload, | ||
) as response: | ||
_LOGGER.debug("Heater response %s", response.status) | ||
if response.status != 200: | ||
_LOGGER.error( | ||
"Failed to set target temperature %s %s", | ||
response.status, | ||
response.reason, | ||
) | ||
return response.status | ||
|
||
async def set_normal_operation_mode(self): | ||
"""Set target temperature.""" | ||
payload = {"mode": "Control individually"} | ||
with async_timeout.timeout(self._timeout): | ||
async with self.websession.post( | ||
f"{self._url}/operation-mode", | ||
payload=payload, | ||
) as response: | ||
_LOGGER.debug("Heater response %s", response.status) | ||
if response.status != 200: | ||
_LOGGER.error( | ||
"Failed to set target temperature %s %s", | ||
response.status, | ||
response.reason, | ||
) | ||
return response.status | ||
|
||
async def get_status(self): | ||
"""Get heater status.""" | ||
try: | ||
with async_timeout.timeout(self._timeout): | ||
async with self.websession.get( | ||
f"{self._url}/control-status", | ||
) as response: | ||
if response.status != 200: | ||
_LOGGER.error( | ||
"Failed to get status %s %s", | ||
response.status, | ||
response.reason, | ||
) | ||
return None, None | ||
return await response.json() | ||
except asyncio.TimeoutError: | ||
return None |