Skip to content

Commit

Permalink
Merge pull request #71 from agodet/glow_onyx_improve
Browse files Browse the repository at this point in the history
update glow information
  • Loading branch information
cyr-ius authored Dec 9, 2024
2 parents 015e3e0 + 60cfa34 commit d284958
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 33 deletions.
46 changes: 25 additions & 21 deletions custom_components/heatzy/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
BLOOM,
CFT_TEMP_H,
CFT_TEMP_L,
CUR_TEMP_L,
CONF_ATTRS,
CONF_CFT_TEMP,
CONF_CUR_MODE,
Expand Down Expand Up @@ -202,12 +203,12 @@ class HeatzyClimateEntityDescription(ClimateEntityDescription):
| ClimateEntityFeature.TURN_OFF
),
heatzy_to_ha_state={
"cft": PRESET_COMFORT,
"eco": PRESET_ECO,
"fro": PRESET_AWAY,
"cft1": PRESET_COMFORT_1,
"cft2": PRESET_COMFORT_2,
"stop": PRESET_NONE,
0: PRESET_COMFORT,
1: PRESET_ECO,
2: PRESET_AWAY,
3: PRESET_COMFORT_1,
4: PRESET_COMFORT_2,
5: PRESET_NONE,
},
ha_to_heatzy_state={
PRESET_COMFORT: "cft",
Expand All @@ -217,6 +218,8 @@ class HeatzyClimateEntityDescription(ClimateEntityDescription):
PRESET_COMFORT_2: "cft2",
PRESET_NONE: "stop",
},
stop="stop",
current_temperature=CUR_TEMP_L,
temperature_high=CFT_TEMP_H,
temperature_low=CFT_TEMP_L,
eco_temperature_high=ECO_TEMP_H,
Expand Down Expand Up @@ -513,30 +516,35 @@ class Glowv1Thermostat(HeatzyPiloteV2Thermostat):
@property
def current_temperature(self) -> float:
"""Return current temperature."""
cur_tempH = self._attrs.get(self.entity_description.temperature_high, 0)
cur_tempL = self._attrs.get(self.entity_description.temperature_low, 0)
return (cur_tempL + (cur_tempH * 256)) / 10
return self._attrs.get(self.entity_description.current_temperature) / 10

@property
def target_temperature_high(self) -> float:
"""Return comfort temperature."""
cft_tempH = self._attrs.get(self.entity_description.temperature_high, 0)
cft_tempL = self._attrs.get(self.entity_description.temperature_low, 0)

if self.preset_mode == PRESET_AWAY:
cft_tempH = 0
cft_tempL = FROST_TEMP * 10

return (cft_tempL + (cft_tempH * 256)) / 10

@property
def target_temperature_low(self) -> float:
"""Return comfort temperature."""
eco_tempH = self._attrs.get(self.entity_description.eco_temperature_high, 0)
eco_tempL = self._attrs.get(self.entity_description.eco_temperature_low, 0)

if self.preset_mode == PRESET_AWAY:
eco_tempH = 0
eco_tempL = FROST_TEMP * 10

return (eco_tempL + (eco_tempH * 256)) / 10

@property
def hvac_action(self) -> HVACAction:
"""Return hvac action ie. heating, off mode."""
if self._attrs.get(CONF_TIMER_SWITCH) == 1:
return HVACMode.AUTO
if self.hvac_mode == HVACMode.OFF:
return HVACAction.OFF
if self.target_temperature and (
Expand All @@ -548,10 +556,11 @@ def hvac_action(self) -> HVACAction:
@property
def hvac_mode(self) -> HVACMode:
"""Return hvac operation ie. heat, cool mode."""
if self._attrs.get(CONF_TIMER_SWITCH) == 1:
if self._attrs.get(CONF_DEROG_MODE) == 1:
return HVACMode.AUTO
if self._attrs.get(CONF_ON_OFF) == 0:
return HVACMode.OFF

return HVACMode.HEAT

@property
Expand All @@ -571,28 +580,23 @@ def target_temperature(self) -> float | None:
@property
def preset_mode(self) -> str | None:
"""Return the current preset mode, e.g., home, away, temp."""
if self._attrs.get(CONF_DEROG_MODE) == 1:
return PRESET_VACATION
if self._attrs.get(CONF_DEROG_MODE) == 2:
return PRESET_BOOST

return self.entity_description.heatzy_to_ha_state.get(
self._attrs.get(CONF_CUR_MODE)
)

async def async_turn_on(self) -> None:
"""Turn device on."""
config = {CONF_ATTRS: {CONF_ON_OFF: 1, CONF_DEROG_MODE: 0}}
config = {CONF_ATTRS: {CONF_ON_OFF: True, CONF_DEROG_MODE: 0}}
await self._handle_action(config, f"Error to turn on {self.unique_id}")

async def async_turn_off(self) -> None:
"""Turn device off."""
config = {CONF_ATTRS: {CONF_ON_OFF: 0, CONF_DEROG_MODE: 0}}
config = {CONF_ATTRS: {CONF_ON_OFF: False, CONF_DEROG_MODE: 0}}
await self._handle_action(config, f"Error to turn on {self.unique_id}")

async def async_turn_auto(self) -> None:
"""Turn device off."""
config = {CONF_ATTRS: {CONF_ON_OFF: 0, CONF_DEROG_MODE: 1}}
config = {CONF_ATTRS: {CONF_ON_OFF: True, CONF_DEROG_MODE: 1}}
await self._handle_action(config, f"Error to turn auto {self.unique_id}")

async def async_set_temperature(self, **kwargs: Any) -> None:
Expand All @@ -613,7 +617,7 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
if await self._async_derog_mode_action(preset_mode) is False:
mode = self.entity_description.ha_to_heatzy_state.get(preset_mode)
config = {CONF_ATTRS: {CONF_MODE: mode, CONF_ON_OFF: 1}}
config = {CONF_ATTRS: {CONF_MODE: mode, CONF_ON_OFF: True}}
if self._attrs.get(CONF_DEROG_MODE, 0) > 0:
config[CONF_ATTRS].update({CONF_DEROG_MODE: 0, CONF_DEROG_TIME: 0})
await self._handle_action(config, f"Error preset mode: {preset_mode}")
Expand Down
1 change: 1 addition & 0 deletions custom_components/heatzy/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CONF_HUMIDITY = "cur_humi"
CONF_IS_ONLINE = "is_online"
CONF_LOCK = "lock_switch"
CONF_LOCK_OTHER = "LOCK_C"
CONF_MODE = "mode"
CONF_MODEL = "product_name"
CONF_ON_OFF = "on_off"
Expand Down
15 changes: 7 additions & 8 deletions custom_components/heatzy/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ boost:
name: Delay
description: Boost delay (minutes)
selector:
select:
translation_key: "boost_delay"
mode: dropdown
options:
- 30
- 60
- 90
- 120
translation_key: "boost_delay"
mode: dropdown
options:
- 30
- 60
- 90
- 120

vacation:
description: Start a vacation
Expand Down
21 changes: 17 additions & 4 deletions custom_components/heatzy/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import HeatzyConfigEntry, HeatzyDataUpdateCoordinator
from .const import CONF_ATTRS, CONF_LOCK, CONF_WINDOW
from .const import CONF_ATTRS, CONF_LOCK, CONF_LOCK_OTHER, CONF_WINDOW, PILOTE_PRO_V1, PILOTE_V1, PILOTE_V2, PILOTE_V3, BLOOM, GLOW, CONF_PRODUCT_KEY
from .entity import HeatzyEntity


@dataclass(frozen=True)
class HeatzySwitchEntityDescription(SwitchEntityDescription):
"""Represents an Flow Sensor."""

attr: str | None = None
attr: str | None = None,
products: list[str] | None = None


SWITCH_TYPES: Final[tuple[HeatzySwitchEntityDescription, ...]] = (
HeatzySwitchEntityDescription(
products=PILOTE_V1 + PILOTE_V2 + PILOTE_V3 + BLOOM + PILOTE_PRO_V1,
key="lock",
name="Lock",
translation_key="lock",
Expand All @@ -39,6 +41,15 @@ class HeatzySwitchEntityDescription(SwitchEntityDescription):
entity_category=EntityCategory.CONFIG,
),
HeatzySwitchEntityDescription(
products=GLOW,
key="lock",
name="Lock",
translation_key="lock",
attr=CONF_LOCK_OTHER,
entity_category=EntityCategory.CONFIG,
),
HeatzySwitchEntityDescription(
products=PILOTE_V1 + PILOTE_V2 + PILOTE_V3 + GLOW + BLOOM + PILOTE_PRO_V1,
key="window",
name="Window",
icon="mdi:window-open-variant",
Expand All @@ -60,9 +71,11 @@ async def async_setup_entry(
entities = []

for unique_id, device in coordinator.data.items():
product_key = device.get(CONF_PRODUCT_KEY)
for description in SWITCH_TYPES:
if device.get(CONF_ATTRS, {}).get(description.attr) is not None:
entities.extend([SwitchEntity(coordinator, description, unique_id)])
if product_key in description.products:
if device.get(CONF_ATTRS, {}).get(description.attr) is not None:
entities.extend([SwitchEntity(coordinator, description, unique_id)])
async_add_entities(entities)


Expand Down

0 comments on commit d284958

Please sign in to comment.