Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge #29

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
159 changes: 158 additions & 1 deletion custom_components/atrea/climate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
import re
import json
from homeassistant.core import HomeAssistant
from homeassistant.config_entries import ConfigEntry
from homeassistant.util import slugify
Expand All @@ -16,6 +17,9 @@
PLATFORM_SCHEMA,
)
from homeassistant.components.climate.const import (
SWING_VERTICAL,
SWING_HORIZONTAL,
SWING_BOTH,
HVACMode
)
from homeassistant.const import (
Expand All @@ -42,6 +46,7 @@
ALL_PRESET_LIST,
ICONS,
HVAC_MODES,
SWING_MODES,
)


Expand Down Expand Up @@ -93,17 +98,30 @@ def __init__(
self._extract_temp = 0.0
self._requested_temp = 0.0
self._requested_power = None
self._co2 = 0.0
self._vent_air_temp = 0.0
self._filter_change = 0
self._defrost = 0
self._sup_req = 0
self._sup_act_flow = 0
self._sup_fan_voltage = 0.0
self._eta_req = 0
self._eta_act_flow = 0
self._eta_fan_voltage = 0.0
self._oda_req = 0
self._oda_act_flow = 0
self._sc_voltage = 0.0
self._active_inputs = []
self._forced_mode = None
self._current_power = None

self._current_preset = None
self._current_hvac_mode = None
self._unit = "Status"
self.air_handling_control = None
self._enabled = False
self._cooling = -1
self._heating = -1
self._zone = -1

self.updatePresetList(preset_list, False)
self.updateFanList(fan_list, False)
Expand Down Expand Up @@ -209,6 +227,20 @@ def extra_state_attributes(self):
attributes["warnings"] = self._warnings
attributes["alerts"] = self._alerts
attributes["program"] = self.air_handling_control
attributes['zone'] = self._zone
attributes['co2'] = self._co2
attributes['vent_air_temp'] = self._vent_air_temp
attributes['filter_change'] = self._filter_change
attributes['defrost'] = self._defrost
attributes['supply_required'] = self._sup_req
attributes['supply_actual_flow'] = self._sup_act_flow
attributes['supply_fan_voltage'] = self._sup_fan_voltage
attributes['eta_required'] = self._eta_req
attributes['eta_actual_flow'] = self._eta_act_flow
attributes['eta_fan_voltage'] = self._eta_fan_voltage
attributes['oda_required'] = self._oda_req
attributes['oda_actual_flow'] = self._oda_act_flow
attributes['sc_voltage'] = self._sc_voltage
attributes["active_inputs"] = self._active_inputs
attributes["forced_mode"] = self._forced_mode.name
attributes["current_power"] = self._current_power
Expand Down Expand Up @@ -276,6 +308,31 @@ def fan_modes(self):
def program(self):
return self.air_handling_control

@property
def hvac_action(self):
if (self._heating == 1):
return HVACAction.HEATING
elif (self._cooling == 1):
return HVACAction.COOLING
elif (self._current_hvac_mode == HVACMode.OFF):
return HVACAction.OFF
else:
return HVACAction.FAN

@property
def swing_modes(self):
return SWING_MODES

@property
def swing_mode(self):
if (self._zone == 0):
return SWING_VERTICAL;
if (self._zone == 1):
return SWING_HORIZONTAL;
if (self._zone == 2):
return SWING_BOTH;
return None

@Throttle(MIN_TIME_BETWEEN_SCANS)
async def async_update(self):
if not self.updatePending:
Expand All @@ -294,6 +351,7 @@ def manualUpdate(self, updateState=True):
self._alerts = []
self._active_inputs = []
if status != False:

if "I10211" in status:
if float(status["I10211"]) > 1300:
self._outside_temp = round(
Expand Down Expand Up @@ -359,6 +417,11 @@ def manualUpdate(self, updateState=True):
else:
self._cooling = -1

if("H10711" in status):
self._zone = int(status["H10711"])
else:
self._zone = -1

# D1..D4 inputs are reported in D10200..D10203
for inpt in range(4):
entry = f"D1020{inpt}"
Expand All @@ -374,6 +437,70 @@ def manualUpdate(self, updateState=True):
if self._current_preset == AtreaMode.OFF:
self._current_hvac_mode = HVACMode.OFF

if('I10205' in status):
# Converting IN1 value to ppm
self._co2 = round(float(status['I10205'])*0.2, 0)
else:
self._co2 = -1

if('I10214' in status):
self._vent_air_temp = float(status['I10214'])/10

if('D11183' in status):
self._filter_change = int(status['D11183'])
else:
self._filter_change = -1

if('D10207' in status):
self._defrost = int(status['D10207'])
else:
self._defrost = -1

if('I11600' in status):
self._sup_req = int(status['I11600'])
else:
self._sup_req = -1

if('I11602' in status):
self._sup_act_flow = int(status['I11602'])
else:
self._sup_act_flow = -1

if('H10200' in status):
self._sup_fan_voltage = float(status['H10200'])/1000
else:
self._sup_fan_voltage = -1.0

if('I11601' in status):
self._eta_req = int(status['I11601'])
else:
self._eta_req = -1

if('I11603' in status):
self._eta_act_flow = int(status['I11603'])
else:
self._eta_act_flow = -1

if('H10201' in status):
self._eta_fan_voltage = float(status['H10201'])/1000
else:
self._eta_fan_voltage = -1.0

if('I11604' in status):
self._oda_req = int(status['I11604'])
else:
self._oda_req = -1

if('I11605' in status):
self._oda_act_flow = int(status['I11605'])
else:
self._oda_act_flow = -1

if('H10204' in status):
self._sc_voltage = float(status['H10204'])/1000
else:
self._sc_voltage = -1.0

program = self.atrea.getProgram()
if program == AtreaProgram.MANUAL:
self.air_handling_control = "Manual"
Expand Down Expand Up @@ -545,3 +672,33 @@ async def async_set_temperature(self, **kwargs):
"Chosen temperature=%s is incorrect. It needs to be between 10 and 40.",
str(temperature),
)

async def async_set_swing_mode(self, swing_mode):
"""Set new target swing operation."""
LOGGER.debug("Setting swing mode to %s", str(swing_mode))

if (swing_mode == SWING_VERTICAL):
self._zone = 0;
elif (swing_mode == SWING_HORIZONTAL):
self._zone = 1;
elif (swing_mode == SWING_BOTH):
self._zone = 2;
else:
LOGGER.warn(
"Zone setting (%s) is not supported.", str(swing_mode))
return

LOGGER.debug("Setting zone to %s", str(self._zone))

# Have to set H10703 as it gets reset by the setProgram method
if(self.atrea.getValue("H10703") == 1):
self.atrea.setCommand("H10703", 2)
self.atrea.setCommand("H10711", int(self._zone))

self.updatePending = True
await self.hass.async_add_executor_job(self.atrea.exec)
await self._coordinator.async_request_refresh()
await self.hass.async_add_executor_job(time.sleep, UPDATE_DELAY / 1000)
self.manualUpdate()
self.updatePending = False

9 changes: 7 additions & 2 deletions custom_components/atrea/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

from homeassistant.components.climate.const import (
ClimateEntityFeature,
HVACMode
HVACMode,
SWING_VERTICAL,
SWING_HORIZONTAL,
SWING_BOTH
)
from pyatrea import AtreaMode

DOMAIN = "atrea"
LOGGER = logging.getLogger(__name__)
UPDATE_DELAY = 1 # update delay disabled
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
SUPPORT_FLAGS = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE | ClimateEntityFeature.PRESET_MODE
SUPPORT_FLAGS = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE | ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.SWING_MODE
DEFAULT_NAME = "Atrea"
STATE_MANUAL = "manual"
STATE_UNKNOWN = "unknown"
Expand Down Expand Up @@ -64,3 +67,5 @@
}

HVAC_MODES = [HVACMode.OFF, HVACMode.AUTO, HVACMode.FAN_ONLY]
# SWING_VERTICAL = Zone 0, SWING_HORIZONTAL = Zone 1, SWING_BOTH = Zone 2
SWING_MODES = [SWING_VERTICAL, SWING_HORIZONTAL, SWING_BOTH]