Skip to content
This repository has been archived by the owner on Jul 10, 2022. It is now read-only.

Commit

Permalink
Separate Heating and Cooling
Browse files Browse the repository at this point in the history
  • Loading branch information
cyr-ius committed May 30, 2020
1 parent 16ef284 commit fe68c2c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 29 deletions.
80 changes: 52 additions & 28 deletions custom_components/cozytouch/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
elif heater.widget == DeviceType.APC_HEATING_ZONE:
devices.append(CozytouchStandaloneAPCHeatingThermostat(heater))
elif heater.widget == DeviceType.APC_HEATING_COOLING_ZONE:
devices.append(CozytouchStandaloneAPCHeatingCoolingThermostat(heater))
devices.append(CozytouchStandaloneAPCHeatingThermostat(heater))
devices.append(CozytouchStandaloneAPCCoolingThermostat(heater))

_LOGGER.info("Found {count} thermostat".format(count=len(devices)))
async_add_entities(devices, True)
Expand Down Expand Up @@ -207,6 +208,7 @@ class CozytouchStandaloneAPCHeatingThermostat(ClimateEntity):
PRESET_AUTO = "Auto"
PRESET_MANU = "Manuel"
PRESET_STOP = "Stop"
PRESET_INTERNAL = "Internal Schedule"

def __init__(self, heater):
"""Initialize the sensor."""
Expand All @@ -222,23 +224,24 @@ def __init__(self, heater):
const.PRESET_ECO,
self.PRESET_MANU,
self.PRESET_STOP,
self.PRESET_INTERNAL,
]
self._hvac_modes = [
const.HVAC_MODE_HEAT_COOL,
const.HVAC_MODE_COOL,
const.HVAC_MODE_HEAT,
const.HVAC_MODE_OFF,
]

@property
def unique_id(self):
"""Return the unique id of this sensor."""
return self.heater.id
return f"heating-{self.heater.id}"

@property
def name(self):
"""Return the name of the sensor."""
return "{place} {heater}".format(
place=self.heater.place.name, heater=self.heater.name
)
return "{heater} Heating".format(heater=self.heater.name)

@property
def supported_features(self):
Expand Down Expand Up @@ -278,8 +281,13 @@ def target_temperature_low(self):
@property
def hvac_mode(self):
"""Return hvac target hvac state."""
if self.heater.is_heating:
_LOGGER.debug(self.heater.thermal_state)
if self.heater.thermal_state == ThermalState.HEATCOOL:
return const.HVAC_MODE_HEAT_COOL
elif self.heater.thermal_state == ThermalState.HEAT:
return const.HVAC_MODE_HEAT
elif self.heater.thermal_state == ThermalState.COOL:
return const.HVAC_MODE_COOL
else:
return const.HVAC_MODE_OFF

Expand Down Expand Up @@ -308,6 +316,8 @@ def preset_mode(self):
return const.PRESET_COMFORT
elif self.heater.operating_mode == ModeState.ABSENCE:
return const.PRESET_AWAY
elif self.heater.operating_mode == ModeState.INTERNAL_SCHEDULING:
return self.PRESET_INTERNAL

return const.PRESET_NONE

Expand All @@ -329,15 +339,17 @@ async def async_set_temperature(self, **kwargs):
_LOGGER.debug(kwargs)
if const.ATTR_TARGET_TEMP_HIGH in kwargs:
await self.heater.set_comfort_temperature(
kwargs[const.ATTR_TARGET_TEMP_HIGH]
kwargs[const.ATTR_TARGET_TEMP_HIGH], thermal_mode="heat"
)
_LOGGER.info(
"Set HIGH TEMP to {temp}".format(
temp=kwargs[const.ATTR_TARGET_TEMP_HIGH]
)
)
if const.ATTR_TARGET_TEMP_LOW in kwargs:
await self.heater.set_eco_temperature(kwargs[const.ATTR_TARGET_TEMP_LOW])
await self.heater.set_eco_temperature(
kwargs[const.ATTR_TARGET_TEMP_LOW], thermal_mode="heat"
)
_LOGGER.info(
"Set LOW TEMP to {temp}".format(temp=kwargs[const.ATTR_TARGET_TEMP_LOW])
)
Expand All @@ -347,7 +359,11 @@ async def async_set_hvac_mode(self, hvac_mode: str) -> None:
if hvac_mode == const.HVAC_MODE_OFF:
await self.heater.set_targeting_mode(ModeState.OFF)
elif hvac_mode == const.HVAC_MODE_HEAT:
await self.heater.set_targeting_mode(ModeState.HEATING)
await self.heater.set_targeting_mode(ThermalState.HEAT)
elif hvac_mode == const.HVAC_MODE_COOL:
await self.heater.set_targeting_mode(ThermalState.COOL)
elif hvac_mode == const.HVAC_MODE_HEAT_COOL:
await self.heater.set_targeting_mode(ThermalState.HEATCOOL)

async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
Expand All @@ -364,12 +380,13 @@ async def async_update(self):
_LOGGER.error("Device data no retrieve {}".format(self.name))


class CozytouchStandaloneAPCHeatingCoolingThermostat(ClimateEntity):
class CozytouchStandaloneAPCCoolingThermostat(ClimateEntity):
"""Representation a thermostat."""

PRESET_AUTO = "Auto"
PRESET_MANU = "Manuel"
PRESET_STOP = "Stop"
PRESET_INTERNAL = "Internal Schedule"

def __init__(self, heater):
"""Initialize the sensor."""
Expand All @@ -385,25 +402,24 @@ def __init__(self, heater):
const.PRESET_ECO,
self.PRESET_MANU,
self.PRESET_STOP,
self.PRESET_INTERNAL,
]
self._hvac_modes = [
const.HVAC_MODE_HEAT_COOL,
const.HVAC_MODE_HEAT,
const.HVAC_MODE_COOL,
const.HVAC_MODE_HEAT,
const.HVAC_MODE_OFF,
]

@property
def unique_id(self):
"""Return the unique id of this sensor."""
return self.heater.id
return f"cooling-{self.heater.id}"

@property
def name(self):
"""Return the name of the sensor."""
return "{place} {heater}".format(
place=self.heater.place.name, heater=self.heater.name
)
return "{heater} Cooling".format(heater=self.heater.name)

@property
def supported_features(self):
Expand Down Expand Up @@ -433,12 +449,12 @@ def device_info(self):
@property
def target_temperature_high(self):
"""Return the high temperature."""
return self.heater.target_comfort_temperature
return self.heater.target_comfort_cooling_temperature

@property
def target_temperature_low(self):
"""Return the low temperature."""
return self.heater.target_comfort_cooling_temperature
return self.heater.target_eco_cooling_temperature

@property
def hvac_mode(self):
Expand All @@ -465,19 +481,21 @@ def is_away_mode_on(self):
@property
def preset_mode(self):
"""Return the current preset mode."""
if self.heater.operating_mode == ModeState.STOP:
_LOGGER.debug(self.heater.cooling_operating_mode)
if self.heater.cooling_operating_mode == ModeState.STOP:
return self.PRESET_STOP
elif self.heater.operating_mode == ModeState.AUTO:
elif self.heater.cooling_operating_mode == ModeState.AUTO:
return self.PRESET_AUTO
elif self.heater.operating_mode == ModeState.MANU:
elif self.heater.cooling_operating_mode == ModeState.MANU:
return self.PRESET_MANU
elif self.heater.operating_mode == ModeState.ECO:
elif self.heater.cooling_operating_mode == ModeState.ECO:
return const.PRESET_ECO
elif self.heater.operating_mode == ModeState.COMFORT:
elif self.heater.cooling_operating_mode == ModeState.COMFORT:
return const.PRESET_COMFORT
elif self.heater.operating_mode == ModeState.ABSENCE:
elif self.heater.cooling_operating_mode == ModeState.ABSENCE:
return const.PRESET_AWAY

elif self.heater.cooling_operating_mode == ModeState.INTERNAL_SCHEDULING:
return self.PRESET_INTERNAL
return const.PRESET_NONE

@property
Expand All @@ -498,15 +516,17 @@ async def async_set_temperature(self, **kwargs):
_LOGGER.debug(kwargs)
if const.ATTR_TARGET_TEMP_HIGH in kwargs:
await self.heater.set_comfort_temperature(
kwargs[const.ATTR_TARGET_TEMP_HIGH]
kwargs[const.ATTR_TARGET_TEMP_HIGH], thermal_mode="cool"
)
_LOGGER.info(
"Set HIGH TEMP to {temp}".format(
temp=kwargs[const.ATTR_TARGET_TEMP_HIGH]
)
)
if const.ATTR_TARGET_TEMP_LOW in kwargs:
await self.heater.set_eco_temperature(kwargs[const.ATTR_TARGET_TEMP_LOW])
await self.heater.set_eco_temperature(
kwargs[const.ATTR_TARGET_TEMP_LOW], thermal_mode="cool"
)
_LOGGER.info(
"Set LOW TEMP to {temp}".format(temp=kwargs[const.ATTR_TARGET_TEMP_LOW])
)
Expand All @@ -516,13 +536,17 @@ async def async_set_hvac_mode(self, hvac_mode: str) -> None:
if hvac_mode == const.HVAC_MODE_OFF:
await self.heater.set_targeting_mode(ModeState.OFF)
elif hvac_mode == const.HVAC_MODE_HEAT:
await self.heater.set_targeting_mode(ModeState.HEATING)
await self.heater.set_targeting_mode(ThermalState.HEAT)
elif hvac_mode == const.HVAC_MODE_COOL:
await self.heater.set_targeting_mode(ThermalState.COOL)
elif hvac_mode == const.HVAC_MODE_HEAT_COOL:
await self.heater.set_targeting_mode(ThermalState.HEATCOOL)

async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
if preset_mode == const.PRESET_AWAY:
preset_mode = ModeState.ABSENCE
await self.heater.set_operating_mode(preset_mode.lower())
await self.heater.set_operating_mode(preset_mode.lower(), thermal_mode="cool")

async def async_update(self):
"""Fetch new state data for this sensor."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/cozytouch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Cozytouch",
"config_flow": true,
"documentation": "https://www.home-assistant.io/components/cozytouch",
"requirements": ["cozytouchpy==1.8.0"],
"requirements": ["cozytouchpy==1.8.1"],
"dependencies": [],
"codeowners": ["@biker91620", "@cyr-ius"]
}

0 comments on commit fe68c2c

Please sign in to comment.