Skip to content

Commit

Permalink
Init version
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Hjelseth Høyer <[email protected]>
  • Loading branch information
Danielhiversen committed Nov 2, 2021
1 parent e78e938 commit 2d79242
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion mill_local/__init__.py
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

0 comments on commit 2d79242

Please sign in to comment.