Skip to content

Commit

Permalink
Merge pull request #18 from funtastix/develop
Browse files Browse the repository at this point in the history
Introduced the ability to set time and treat time setting mode as known
  • Loading branch information
funtastix authored Sep 25, 2023
2 parents 1c7ce7a + 2f2de6b commit 40255d0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
9 changes: 8 additions & 1 deletion pyrinnaitouch/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
MODE_EVAP_CMD = '{"SYST": {"OSS": {"MD": "E" } } }'
MODE_HEAT_CMD = '{"SYST": {"OSS": {"MD": "H" } } }'

SYSTEM_ENTER_TIME_SETTING = '{"SYST": {"OSS": {"ST": "C"}}}'
SYSTEM_SET_TIME = '{{"SYST": {{"STM": {{"DY": "{day}", "TM": "{time}"}} }} }}'
SYSTEM_SAVE_TIME = '{"SYST": {"STM": {"SV": "Y"}}}'

UNIT_ON_CMD = '{{"{unit_id}": {{"OOP": {{"ST": "N" }} }} }}'
UNIT_OFF_CMD = '{{"{unit_id}": {{"OOP": {{"ST": "F" }} }} }}'
UNIT_CIRC_FAN_ON = '{{"{unit_id}": {{"OOP": {{"ST": "Z" }} }} }}'
Expand Down Expand Up @@ -85,5 +89,8 @@
UNIT_ON_CMD,
EVAP_ON_CMD,
UNIT_SET_AUTO,
UNIT_SET_MANUAL
UNIT_SET_MANUAL,
SYSTEM_ENTER_TIME_SETTING,
SYSTEM_SET_TIME,
SYSTEM_SAVE_TIME,
]
2 changes: 1 addition & 1 deletion pyrinnaitouch/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def receive_data(self) -> None:
if temp:
# _LOGGER.debug("Received data: (%s)", temp.decode())
data = temp
if str(data) == "*HELLO":
if str(data) == "*HELLO*":
_LOGGER.debug(
"Received friendly HELLO from unit,not processing this one"
)
Expand Down
36 changes: 31 additions & 5 deletions pyrinnaitouch/system.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Main system control"""
import logging
import queue
from datetime import datetime
from typing import Any

from .const import RinnaiSystemMode, RinnaiUnitId
Expand Down Expand Up @@ -32,6 +33,9 @@
MODE_HEAT_CMD,
EVAP_COMMANDS,
MODE_COMMANDS,
SYSTEM_ENTER_TIME_SETTING,
SYSTEM_SAVE_TIME,
SYSTEM_SET_TIME,
UNIT_ADVANCE,
UNIT_ADVANCE_CANCEL,
UNIT_CIRC_FAN_ON,
Expand Down Expand Up @@ -103,13 +107,21 @@ def poll_loop(self) -> None:
if "sys.exit" in new_status_json:
self._connection.shutdown()
break
status = RinnaiSystemStatus()
res = status.handle_status(new_status_json)
if res:
self._status = status
if (
isinstance(new_status_json, list)
and "SYST" in new_status_json[0]
and "STM" in new_status_json[0]["SYST"]
):
self._status.set_timesetting(True)
self._on_updated()
else:
self._connection.log_json_error()
status = RinnaiSystemStatus()
res = status.handle_status(new_status_json)
if res:
self._status = status
self._on_updated()
else:
self._connection.log_json_error()
_LOGGER.debug("Shutting down the polling thread")

async def set_cooling_mode(self) -> bool:
Expand Down Expand Up @@ -364,6 +376,20 @@ async def set_evap_zone_manual(self, zone: str) -> bool:
return True
return False

async def set_system_time(self, set_datetime: datetime = None) -> bool:
"""Set system time."""
now = datetime.now()
if set_datetime is not None and isinstance(set_datetime, datetime):
now = set_datetime
set_time = now.strftime("%H:%M")
set_day = now.strftime("%a").upper()
result = self.validate_and_send(SYSTEM_ENTER_TIME_SETTING)
cmd = SYSTEM_SET_TIME
if self.validate_command(cmd):
result = self.send_command(cmd.format(day=set_day, time=set_time)) and result
result = self.validate_and_send(SYSTEM_SAVE_TIME) and result
return result

def get_stored_status(self) -> RinnaiSystemStatus:
"""Get the current status without a refresh."""
return self._status
Expand Down
6 changes: 6 additions & 0 deletions pyrinnaitouch/system_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self) -> None:

#faults
self.has_fault: bool = False
self.is_timesetting: bool = False

def handle_status(self, status_json: Any) -> bool:
"""Handle the JSON response from the system."""
Expand Down Expand Up @@ -141,3 +142,8 @@ def set_capabilities(self, avm: Any) -> None:
self.capabilities |= RinnaiCapabilities.COOLER
if get_attribute(avm, COOLING_EVAPORATIVE, None) == MODULE_ENABLED:
self.capabilities |= RinnaiCapabilities.EVAP


def set_timesetting(self, is_setting: bool) -> None:
"""Set system into time setting mode"""
self.is_timesetting = is_setting
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
setup(
name="pyrinnaitouch",
packages=find_packages(exclude=["tests", "tests.*"]),
version="0.12.13",
version="0.12.14",
license="mit",
description="A python interface to the Rinnai Touch Wifi controller",
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
author="Funtastix",
url="https://github.com/funtastix/pyrinnaitouch",
download_url="https://github.com/funtastix/pyrinnaitouch/archive/refs/tags/v0.12.13.tar.gz",
download_url="https://github.com/funtastix/pyrinnaitouch/archive/refs/tags/v0.12.14.tar.gz",
keywords=[
"Rinnai Touch",
"Brivis",
Expand Down

0 comments on commit 40255d0

Please sign in to comment.