Skip to content

Commit

Permalink
Merge pull request #56 from cyr-ius/websocket
Browse files Browse the repository at this point in the history
Merge websocket mode to master branch
  • Loading branch information
cyr-ius authored May 1, 2024
2 parents f36f106 + c377a47 commit 94b0705
Show file tree
Hide file tree
Showing 12 changed files with 427 additions and 85 deletions.
19 changes: 12 additions & 7 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

title: ""
labels: ""
assignees: ""
---

**Model**

<!--Specify the model listed on the box or the convector or the commercial name.
(not what is written in HA)
Specifier le nom du boitier ou le nom commercial du produit. pas ce qui apparait dans HA mais ce qui est ecrit surl étiquette du produit ou votre facture.-->
Model:

Model:

**Describe the bug**

<!--A clear and concise description of what the bug is.
Decrire le plus clairement votre pbl et si cela marchait avant sur une version précédente ou si cela n a jamais marcher.
Decrire le plus clairement votre pbl et si cela marchait avant sur une version précédente ou si cela n a jamais marcher.
(Issue du genre , j ai un soucis le truc marche pas, et cela marche dans le smartphone. Je droppe votre demande direction jupiter.Cela m aide en rien sans le fichier de diag)-->

**Diagnostics & Debug file**

<!--Please add the diagnostics file. This action runs all APIs and stores them in raw format. Sensitive data is hidden
Ajouter le fichier de diagnostic (et c est pas optionnel)
Activer au besoin le mode Debug ,faite quelques teste et soumette le fichier de debug. Ce fichier peut etre optionnel a l ouverture du pbl.-->

![Screenshot](https://github.com/cyr-ius/hass-audiconnect/assets/1258123/28916bd3-66fd-4df5-bf3c-93012c555051)

**Screenshots**

<!--If applicable, add screenshots to help explain your problem.
Quelque capture d ecran si cela peut aider-->

**Additional context**

<!--Add any other context about the problem here.
Tout ce que vous jugez utile.
Ah autre chose, si cela marchait le lundi et que cela ne marche plus le mardi. Et que vous avez pas fait de mise a jour de mon addons. Mes pouvoirs de télépathie ou de telekinesie sont quasi nulle. j arrive pas a changer le code par la pensée sur votre Home Assistant.
Donc soit on a soucis chez Heatzy, soit vous avez modifier des choses de votre côté.
N hésiter pas ouvrir un issue mais dans ce cas, une description précise est requise -->

20 changes: 18 additions & 2 deletions custom_components/heatzy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant

from .const import DOMAIN, PLATFORMS
from .const import CONF_WEBSOCKET, DOMAIN, PLATFORMS
from .coordinator import HeatzyDataUpdateCoordinator

_LOGGER = logging.getLogger(__name__)
Expand All @@ -16,9 +16,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Heatzy as config entry."""
hass.data.setdefault(DOMAIN, {})

# Interim code to ensure the transition
if entry.options.get(CONF_WEBSOCKET) is None:
hass.config_entries.async_update_entry(entry, options={CONF_WEBSOCKET: True})
# End

coordinator = HeatzyDataUpdateCoordinator(hass, entry)
await coordinator.async_config_entry_first_refresh()

entry.async_on_unload(entry.add_update_listener(_async_update_listener))

hass.data[DOMAIN][entry.entry_id] = coordinator
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

Expand All @@ -28,5 +35,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
hass.data[DOMAIN].pop(entry.entry_id)
coordinator: HeatzyDataUpdateCoordinator = hass.data[DOMAIN].pop(entry.entry_id)
await coordinator.api.async_close()
if coordinator.unsub:
coordinator.unsub()

return unload_ok


async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry):
"""Reload if change option."""
await hass.config_entries.async_reload(entry.entry_id)
130 changes: 106 additions & 24 deletions custom_components/heatzy/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Any

import voluptuous as vol
from heatzypy.exception import HeatzyException
from homeassistant.components.climate import (
ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW,
Expand All @@ -27,14 +26,14 @@
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from wsheatzypy.exception import HeatzyException

from . import HeatzyDataUpdateCoordinator
from .const import (
BLOOM,
CFT_TEMP_H,
CFT_TEMP_L,
CONF_ALIAS,
CONF_ATTR,
CONF_ATTRS,
CONF_CFT_TEMP,
CONF_CUR_MODE,
Expand All @@ -49,6 +48,7 @@
CONF_PRODUCT_KEY,
CONF_TIMER_SWITCH,
CONF_VERSION,
CONF_WEBSOCKET,
CUR_TEMP_H,
CUR_TEMP_L,
DOMAIN,
Expand Down Expand Up @@ -129,9 +129,17 @@ def __init__(
model=coordinator.data[unique_id].get(CONF_MODEL),
name=coordinator.data[unique_id][CONF_ALIAS],
)
self._attr = coordinator.data[unique_id].get(CONF_ATTR, {})
self._attr = coordinator.data[unique_id].get(CONF_ATTRS, {})
self._attr_available = coordinator.data[unique_id].get(CONF_IS_ONLINE, True)

# Interim code to ensure the transition
self._ws_mode = coordinator.config_entry.options.get(CONF_WEBSOCKET)
if self._ws_mode:
self.coordinator.api.async_control_device = (
self.coordinator.api.websocket.async_control_device
)
# End

@property
def hvac_action(self) -> HVACAction:
"""Return hvac action ie. heat, cool mode."""
Expand Down Expand Up @@ -191,9 +199,9 @@ async def async_boost_mode(self, delay: int) -> None:
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
_LOGGER.debug(self.coordinator.data)
self._attr = self.coordinator.data.get(self.unique_id, {}).get(CONF_ATTR, {})
self._attr_available = self.coordinator.data.get(self.unique_id, {}).get(
_LOGGER.debug("------- UPDATE CLIMATE %s ------- ", self.unique_id)
self._attr = self.coordinator.data[self.unique_id].get(CONF_ATTRS, {})
self._attr_available = self.coordinator.data[self.unique_id].get(
CONF_IS_ONLINE, True
)
self.async_write_ha_state()
Expand Down Expand Up @@ -231,7 +239,12 @@ async def async_turn_auto(self) -> None:
}
},
)
await self.coordinator.async_request_refresh()

# Interim code to ensure the transition
if not self._ws_mode:
await self.coordinator.async_request_refresh()
# End

except HeatzyException as error:
_LOGGER.error("Error while turn off (%s)", error)

Expand All @@ -242,7 +255,12 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
self.unique_id,
{"raw": self.HA_TO_HEATZY_STATE.get(preset_mode)},
)
await self.coordinator.async_request_refresh()

# Interim code to ensure the transition
if not self._ws_mode:
await self.coordinator.async_request_refresh()
# End

except HeatzyException as error:
_LOGGER.error("Error while preset mode: %s (%s)", preset_mode, error)

Expand All @@ -254,7 +272,7 @@ class HeatzyPiloteV2Thermostat(HeatzyThermostat):
# DEROG_MODE = 1 is VACATION Mode
# DEROG_MODE = 2 is BOOST Mode
HEATZY_TO_HA_STATE = {"cft": PRESET_COMFORT, "eco": PRESET_ECO, "fro": PRESET_AWAY}
HA_TO_HEATZY_STATE = {PRESET_COMFORT: 0, PRESET_ECO: 1, PRESET_AWAY: 2}
HA_TO_HEATZY_STATE = {PRESET_COMFORT: "cft", PRESET_ECO: "eco", PRESET_AWAY: "fro"}
HEATZY_STOP = "stop"
_attr_preset_modes = [PRESET_COMFORT, PRESET_ECO, PRESET_AWAY, PRESET_BOOST]

Expand Down Expand Up @@ -282,12 +300,22 @@ async def async_turn_on(self) -> None:
}
},
)
await self.coordinator.async_request_refresh()

# Interim code to ensure the transition
if not self._ws_mode:
await self.coordinator.async_request_refresh()
# End

await self.coordinator.api.async_control_device(
self.unique_id,
{CONF_ATTRS: {CONF_MODE: self.HA_TO_HEATZY_STATE[PRESET_COMFORT]}},
)
await self.coordinator.async_request_refresh()

# Interim code to ensure the transition
if not self._ws_mode:
await self.coordinator.async_request_refresh()
# End

except HeatzyException as error:
_LOGGER.error("Error to turn on (%s)", error)

Expand All @@ -308,12 +336,22 @@ async def async_turn_off(self) -> None:
}
},
)
await self.coordinator.async_request_refresh()

# Interim code to ensure the transition
if not self._ws_mode:
await self.coordinator.async_request_refresh()
# End

await self.coordinator.api.async_control_device(
self.unique_id,
{CONF_ATTRS: {CONF_MODE: self.HEATZY_STOP}},
)
await self.coordinator.async_request_refresh()

# Interim code to ensure the transition
if not self._ws_mode:
await self.coordinator.async_request_refresh()
# End

except HeatzyException as error:
_LOGGER.error("Error to turn off (%s)", error)

Expand All @@ -330,7 +368,12 @@ async def async_turn_auto(self) -> None:
}
},
)
await self.coordinator.async_request_refresh()

# Interim code to ensure the transition
if not self._ws_mode:
await self.coordinator.async_request_refresh()
# End

except HeatzyException as error:
_LOGGER.error("Error to turn auto (%s)", error)

Expand All @@ -347,7 +390,12 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
config[CONF_ATTRS].update({CONF_DEROG_MODE: 0, CONF_DEROG_TIME: 0})
try:
await self.coordinator.api.async_control_device(self.unique_id, config)
await self.coordinator.async_request_refresh()

# Interim code to ensure the transition
if not self._ws_mode:
await self.coordinator.async_request_refresh()
# End

except HeatzyException as error:
_LOGGER.error("Error to set preset mode: %s (%s)", preset_mode, error)

Expand All @@ -369,7 +417,12 @@ async def _async_derog_mode(self, mode: int, delay: int) -> None:

try:
await self.coordinator.api.async_control_device(self.unique_id, config)
await self.coordinator.async_request_refresh()

# Interim code to ensure the transition
if not self._ws_mode:
await self.coordinator.async_request_refresh()
# End

except HeatzyException as error:
_LOGGER.error("Error to set derog mode: %s (%s)", mode, error)

Expand Down Expand Up @@ -468,10 +521,14 @@ async def async_turn_on(self) -> None:
# When turning ON ensure PROGRAM and VACATION mode are OFF
try:
await self.coordinator.api.async_control_device(
self.unique_id,
{CONF_ATTRS: {CONF_ON_OFF: 1, CONF_DEROG_MODE: 0}},
self.unique_id, {CONF_ATTRS: {CONF_ON_OFF: 1, CONF_DEROG_MODE: 0}}
)
await self.coordinator.async_request_refresh()

# Interim code to ensure the transition
if not self._ws_mode:
await self.coordinator.async_request_refresh()
# End

except HeatzyException as error:
_LOGGER.error("Error to turn on : %s", error)

Expand All @@ -481,7 +538,12 @@ async def async_turn_off(self) -> None:
await self.coordinator.api.async_control_device(
self.unique_id, {CONF_ATTRS: {CONF_ON_OFF: 0, CONF_DEROG_MODE: 0}}
)
await self.coordinator.async_request_refresh()

# Interim code to ensure the transition
if not self._ws_mode:
await self.coordinator.async_request_refresh()
# End

except HeatzyException as error:
_LOGGER.error("Error to turn off : %s", error)

Expand All @@ -492,7 +554,12 @@ async def async_turn_auto(self) -> None:
await self.coordinator.api.async_control_device(
self.unique_id, {CONF_ATTRS: {CONF_ON_OFF: 1, CONF_DEROG_MODE: 1}}
)
await self.coordinator.async_request_refresh()

# Interim code to ensure the transition
if not self._ws_mode:
await self.coordinator.async_request_refresh()
# End

except HeatzyException as error:
_LOGGER.error("Error to turn auto : %s", error)

Expand All @@ -514,7 +581,12 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
}
},
)
await self.coordinator.async_request_refresh()

# Interim code to ensure the transition
if not self._ws_mode:
await self.coordinator.async_request_refresh()
# End

except HeatzyException as error:
_LOGGER.error("Error to set temperature (%s)", error)

Expand All @@ -531,7 +603,12 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
config[CONF_ATTRS].update({CONF_DEROG_MODE: 0})
try:
await self.coordinator.api.async_control_device(self.unique_id, config)
await self.coordinator.async_request_refresh()

# Interim code to ensure the transition
if not self._ws_mode:
await self.coordinator.async_request_refresh()
# End

except HeatzyException as error:
_LOGGER.error("Error to set preset mode: %s (%s)", preset_mode, error)

Expand Down Expand Up @@ -610,7 +687,12 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
}
},
)
await self.coordinator.async_request_refresh()

# Interim code to ensure the transition
if not self._ws_mode:
await self.coordinator.async_request_refresh()
# End

except HeatzyException as error:
_LOGGER.error("Error to set temperature (%s)", error)

Expand Down
Loading

0 comments on commit 94b0705

Please sign in to comment.