Skip to content

Commit

Permalink
Merge pull request #4 from explosivo22/dev
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
explosivo22 committed Oct 17, 2021
2 parents d1a3610 + 18b8e50 commit 254b32d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 64 deletions.
Binary file modified .vs/VSWorkspaceState.json
Binary file not shown.
Binary file modified .vs/aiorinnai/v16/.suo
Binary file not shown.
Binary file modified .vs/slnx.sqlite
Binary file not shown.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,14 @@ async def main() -> None:

#Start Recirculation
#Last variable is duration in minutes
start_recirculation = await api.device.start_recirculation(user_info["id"], first_device_id, 5)

print(start_recirculation)
start_recirculation = await api.device.start_recirculation(device_info['data']['getDevices'], 5)

#Stop Recirculation
stop_recirculation = await api.device.stop_recirculation(user_info["id"], first_device_id)

print(stop_recirculation)
stop_recirculation = await api.device.stop_recirculation(device_info['data']['getDevices'])

#Set Temperature
#Last variable is the temperature in increments of 5
set_temperature = await api.device.set_temperature(user_info["id"], first_device_id, 130)
set_temperature = await api.device.set_temperature(device_info['data']['getDevices'], 130)


asyncio.run(main())
Expand Down
78 changes: 22 additions & 56 deletions aiorinnai/device.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Define /device endpoints."""
from typing import Awaitable, Callable

from .const import GET_DEVICE_PAYLOAD, GET_PAYLOAD_HEADERS, COMMAND_URL, COMMAND_HEADERS
from .const import GET_DEVICE_PAYLOAD, GET_PAYLOAD_HEADERS, COMMAND_URL, COMMAND_HEADERS, SHADOW_ENDPOINT


class Device: # pylint: disable=too-few-public-methods
Expand Down Expand Up @@ -58,61 +58,27 @@ async def do_maintenance_retrieval(self, user_uuid: str, thing_name: str) -> Non

return await self._request("post", COMMAND_URL, data=data, headers=COMMAND_HEADERS)

async def _set_shadow(self, dev, attribute, value):
data = {
'user': dev['user_uuid'],
'thing': dev['thing_name'],
'attribute': attribute,
'value': value
}
headers = {
'User-Agent': 'okhttp/3.12.1'
}
r = await self._request('post',SHADOW_ENDPOINT, data=data, headers=headers)
return r

async def start_recirculation(self, user_uuid: str, device_id: str, duration: int, additional_params={}) -> None:
"""start recirculation on the specified device"""

payload = "user=%s&thing=%s&attribute=set_priority_status&value=true" % (user_uuid, device_id)

await self._request(
"post",
COMMAND_URL,
data=payload,
headers=COMMAND_HEADERS
)

payload = "user=%s&thing=%s&attribute=recirculation_duration&value=%s" % (user_uuid, device_id, duration)
await self._request(
"post",
COMMAND_URL,
data=payload,
headers=COMMAND_HEADERS
)

payload = "user=%s&thing=%s&attribute=set_recirculation_enabled&value=true" % (user_uuid, device_id)
await self._request(
"post",
COMMAND_URL,
data=payload,
headers=COMMAND_HEADERS
)

return True

async def stop_recirculation(self, user_uuid: str, device_id: str) -> None:
payload = "user=%s&thing=%s&attribute=set_recirculation_enabled&value=false" % (user_uuid, device_id)

await self._request(
"post",
COMMAND_URL,
data=payload,
headers=COMMAND_HEADERS
)

return True

async def set_temperature(self, user_uuid: str, device_id: str, temperature: int) -> None:
"""set the temperature of the hot water heater"""

#check if the temperature is a multiple of 5. Rinnai only takes temperatures this way
if temperature % 5 == 0:
payload="user=%s&thing=%s&attribute=set_domestic_temperature&value=%s" % (user_uuid, device_id, temperature)
async def set_temperature(self, dev, temp: int):
await self._set_shadow(dev, 'set_priority_status', 'true')
return await self._set_shadow(dev, 'set_domestic_temperature', str(temp))

await self._request(
"post",
COMMAND_URL,
data=payload,
headers=COMMAND_HEADERS
)
async def stop_recirculation(self, dev):
return await self._set_shadow(dev, 'set_recirculation_enabled', 'false')

return True
async def start_recirculation(self, dev, duration: int):
await self._set_shadow(dev, 'set_priority_status', 'true')
await self._set_shadow(dev, 'recirculation_duration', str(duration))
return await self._set_shadow(dev, 'set_recirculation_enabled', 'true')
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name="aiorinnai",
version="0.2.2",
version="0.2.3",
description="Python interface for Rinnai Control-R API",
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 254b32d

Please sign in to comment.