Skip to content

Commit

Permalink
Merge pull request #85 from funtastix/develop
Browse files Browse the repository at this point in the history
Introduced the ability to set time via a service and added a sensor to monitor time setting mode
  • Loading branch information
funtastix authored Sep 25, 2023
2 parents 357592a + 2624553 commit 79e3042
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 4 deletions.
33 changes: 33 additions & 0 deletions custom_components/rinnaitouch/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async def async_setup_entry(
RinnaiPumpOperatingBinarySensorEntity(ip_address, name),
RinnaiCoolerBusyBinarySensorEntity(ip_address, name),
RinnaiFanOperatingBinarySensorEntity(ip_address, name),
RinnaiTimeSettingSensorEntity(ip_address, name),
]
)
if entry.data.get(CONF_ZONE_A):
Expand Down Expand Up @@ -321,6 +322,38 @@ def available(self):
return True


class RinnaiTimeSettingSensorEntity(RinnaiBinarySensorEntity):
"""Binary sensor for signaling the system is in time setting mode."""

def __init__(self, ip_address, name):
super().__init__(ip_address, name)
self._attr_name = name + " Time Setting Sensor"
self._attr_status_attr = "is_timesetting"

@property
def icon(self):
"""Return the icon to use in the frontend for this device."""
if self.is_on:
return "mdi:clock-alert-outline"
return "mdi:clock-outline"

@property
def is_on(self):
"""If the sensor is currently on or off."""
state: RinnaiSystemStatus = self._system.get_stored_status()
if self.available:
return state.is_timesetting
return False

@property
def available(self):
"""If the sensor is currently available."""
state: RinnaiSystemStatus = self._system.get_stored_status()
if not state.has_fault:
return True
return False


class RinnaiZoneStateBinarySensorEntity(RinnaiBinarySensorEntity):
"""Binary sensor for preheating on/off during heater operation."""

Expand Down
19 changes: 18 additions & 1 deletion custom_components/rinnaitouch/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from __future__ import annotations
import asyncio
from datetime import timedelta
from datetime import timedelta, datetime

import logging

Expand All @@ -43,6 +43,8 @@
)
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.entity_registry import async_entries_for_device
from homeassistant.helpers import config_validation as cv, entity_platform
import voluptuous as vol

from .const import (
PRESET_AUTO,
Expand All @@ -62,6 +64,7 @@
CONF_ZONE_D,
CONF_ZONE_COMMON,
DEFAULT_NAME,
SET_DATETIME,
)

SUPPORT_FLAGS_MAIN = (
Expand All @@ -75,6 +78,8 @@

SCAN_INTERVAL = timedelta(seconds=5)

SERVICE_SET_TIME = "rinnai_set_time"


async def async_setup_entry(hass, entry, async_add_entities):
"""Set up climate entities."""
Expand Down Expand Up @@ -109,6 +114,14 @@ async def async_setup_entry(hass, entry, async_add_entities):
async_add_entities(
[RinnaiTouchZone(hass, ip_address, name, "U", temperature_entity_common)]
)
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(
SERVICE_SET_TIME,
{
vol.Optional(SET_DATETIME): cv.datetime,
},
"set_system_time"
)
return True


Expand Down Expand Up @@ -429,6 +442,10 @@ def set_swing_mode(self, swing_mode):
"""Set new target swing operation."""
return False

async def set_system_time(self, set_datetime: datetime = None):
"""Set the system time."""
await self._system.set_system_time(set_datetime)

async def async_set_temperature(self, **kwargs):
"""Set new target temperature."""
if kwargs.get(ATTR_TEMPERATURE) is not None:
Expand Down
1 change: 1 addition & 0 deletions custom_components/rinnaitouch/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
CONF_ZONE_C = "Zone C"
CONF_ZONE_D = "Zone D"
CONF_ZONE_COMMON = "Common Zone"
SET_DATETIME = "set_datetime"
4 changes: 2 additions & 2 deletions custom_components/rinnaitouch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"documentation": "https://github.com/funtastix/rinnaitouch",
"issue_tracker": "https://github.com/funtastix/rinnaitouch/issues",
"codeowners": [ "@funtastix" ],
"requirements": [ "pyrinnaitouch>=0.12.13" ],
"requirements": [ "pyrinnaitouch>=0.12.14" ],
"config_flow": true,
"version": "0.12.13",
"version": "0.12.14",
"iot_class": "local_push"
}
2 changes: 1 addition & 1 deletion custom_components/rinnaitouch/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
async_timeout>=3.0.1
asyncio>=3.4.3
pyrinnaitouch>=0.12.13
pyrinnaitouch>=0.12.14
29 changes: 29 additions & 0 deletions custom_components/rinnaitouch/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Service ID
rinnai_set_time:
# If the service accepts entity IDs, target allows the user to specify entities by
# entity, device, or area. If `target` is specified, `entity_id` should not be
# defined in the `fields` map. By default it shows only targets matching entities
# from the same domain as the service, but if further customization is required,
# target supports the entity, device, and area selectors
# (https://www.home-assistant.io/docs/blueprint/selectors/). Entity selector
# parameters will automatically be applied to device and area, and device selector
# parameters will automatically be applied to area.
target:
entity:
domain: climate
integration: rinnaitouch
# Different fields that your service accepts
fields:
# Key of the field
set_datetime:
# Whether or not field is required (default = false)
required: false
# Advanced fields are only shown when the advanced mode is enabled for the user
# (default = false)
advanced: false
# Example value that can be passed for this field
example: "2023-01-01T12:00:00+0000"
# Selector (https://www.home-assistant.io/docs/blueprint/selectors/) to control
# the input UI for this field
selector:
datetime:

0 comments on commit 79e3042

Please sign in to comment.