Skip to content

Commit

Permalink
update glow information
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Godet committed Dec 8, 2024
1 parent 7329cdd commit 0f0fe98
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
33 changes: 21 additions & 12 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 @@ -210,16 +211,17 @@ class HeatzyClimateEntityDescription(ClimateEntityDescription):
| ClimateEntityFeature.TURN_OFF
),
heatzy_to_ha_state={
"cft": PRESET_COMFORT,
"eco": PRESET_ECO,
"fro": PRESET_AWAY,
0: PRESET_COMFORT,
1: PRESET_ECO,
2: PRESET_AWAY,
},
ha_to_heatzy_state={
PRESET_COMFORT: "cft",
PRESET_ECO: "eco",
PRESET_AWAY: "fro",
},
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 @@ -528,15 +530,17 @@ 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_tempL = self._attrs.get(self.entity_description.temperature_high, 0)
cft_tempH = self._attrs.get(self.entity_description.temperature_low, 0)
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 = 70

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

Expand All @@ -545,6 +549,11 @@ 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 = 70

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

@property
Expand Down Expand Up @@ -597,17 +606,17 @@ def preset_mode(self) -> str | None:

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 @@ -628,7 +637,7 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
if mode := self.entity_description.ha_to_heatzy_state.get(preset_mode):
await self._handle_preset_mode(
preset_mode, {CONF_ATTRS: {CONF_MODE: mode, CONF_ON_OFF: 1}}
preset_mode, {CONF_ATTRS: {CONF_MODE: mode, CONF_ON_OFF: True}}
)
else:
await self._handle_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
22 changes: 18 additions & 4 deletions custom_components/heatzy/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from dataclasses import dataclass
import logging
from itertools import product
from typing import Final

from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
Expand All @@ -12,26 +13,37 @@
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",
attr=CONF_LOCK,
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 @@ -53,9 +65,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 0f0fe98

Please sign in to comment.