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

Add follow me support for Breez Max #38

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion custom_components/cielo_home/cielohomedevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
FAN_LOW_VALUE,
FAN_MEDIUM,
FAN_MEDIUM_VALUE,
FOLLOW_ME_OFF,
FOLLOW_ME_ON,
PRESET_MODES,
PRESET_NONE,
PRESET_TURBO,
Expand Down Expand Up @@ -252,6 +254,24 @@ def _send_fan_speed(self, value) -> None:
self._device["latestAction"]["fanspeed"] = value
self._send_msg(action, "fanspeed", action["fanspeed"])

def send_follow_me_on(self) -> None:
"""c"""
self.send_follow_me(FOLLOW_ME_ON)

def send_follow_me_off(self) -> None:
"""c"""
self.send_follow_me(FOLLOW_ME_OFF)

def send_follow_me(self, value) -> None:
"""c"""
if self._device["latestAction"]["followme"] == value:
return

action = self._get_action()
action["followme"] = value
self._device["latestAction"]["followme"] = value
self._send_msg(action, "followme", action["followme"])

def send_swing_adjust(self) -> None:
"""c"""
self._send_swing(SWING_ADJUST_VALUE)
Expand Down Expand Up @@ -375,7 +395,12 @@ def get_is_turbo_mode(self) -> bool:

def get_is_followme_mode(self) -> bool:
"""c"""
return self._device["appliance"]["followme"] != ""
try:
return self._device["appliance"]["followme"] != ""
except KeyError:
pass

return False

def get_range_temp(self) -> str:
"""c"""
Expand Down Expand Up @@ -440,6 +465,10 @@ def get_mode(self) -> str:
def get_power(self) -> str:
"""c"""
return self._device["latestAction"]["power"]

def get_follow_me(self) -> str:
"""c"""
return self._device["latestAction"]["followme"]

def get_light(self) -> str:
"""c"""
Expand Down Expand Up @@ -511,6 +540,11 @@ def _get_action(self) -> object:
except KeyError:
action["light"] = "off"

try:
action["followme"] = self._device["latestAction"]["followme"]
except KeyError:
pass

return action

def get_fan_modes(self) -> list[str]:
Expand Down Expand Up @@ -808,6 +842,11 @@ def data_receive(self, data) -> None:
except KeyError:
pass

try:
self._device["latestAction"]["followme"] = data["action"]["followme"]
except KeyError:
pass

# self.dispatch_state_timer()
self.dispatch_state_updated()

Expand Down
3 changes: 3 additions & 0 deletions custom_components/cielo_home/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@
FAN_LOW_VALUE = "low"
FAN_MEDIUM_VALUE = "medium"
FAN_HIGH_VALUE = "high"

FOLLOW_ME_ON = "on"
FOLLOW_ME_OFF = "off"
41 changes: 41 additions & 0 deletions custom_components/cielo_home/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.components.climate import HVACMode

from .cielohomedevice import CieloHomeDevice
from .const import DOMAIN
Expand All @@ -23,13 +24,21 @@ async def async_setup_entry(
entities.append(
CieloHomeSwitchPower(device, "Power", device.get_uniqueid() + "_power")
)

if device.get_is_appliance_is_freezepoin_display():
entities.append(
CieloHomeSwitchFreezingPoint(
device, "Freezing Point", device.get_uniqueid() + "FreezingPoint"
)
)

if device.get_is_followme_mode():
entities.append(
CieloHomeSwitchFollowMe(
device, "Follow Me", device.get_uniqueid() + "_follow_me"
)
)

# if device.get_is_light_mode():
# entities.append(
# CieloHomeSwitchLight(device, "Light", device.get_uniqueid() + "Light")
Expand Down Expand Up @@ -95,6 +104,38 @@ def _update_internal_state(self):
"""c"""
self._attr_is_on = self.is_power_on()

class CieloHomeSwitchFollowMe(CieloHomeEntity, SwitchEntity):
"""Representation of a Bond generic device."""

def __init__(self, device: CieloHomeDevice, name, unique_id) -> None:
"""c"""
super().__init__(device, device.get_name() + " " + name, unique_id)
self._attr_is_on = self.is_follow_me()
self._attr_available = self.is_available()
self._attr_icon = "mdi:remote"
self._device.add_listener(self)

def turn_on(self, **kwargs: Any) -> None:
"""Turn follow me on."""
self._device.send_follow_me_on()
self._update_internal_state()

def turn_off(self, **kwargs: Any) -> None:
"""Turn follow me off."""
self._device.send_follow_me_off()
self._update_internal_state()

def is_follow_me(self, **kwargs: Any) -> bool:
"""s"""
return self._device.get_follow_me() == "on"

def is_available(self) -> bool:
return self._device.get_power() == "on" and self._device.get_hvac_mode() in [HVACMode.HEAT, HVACMode.COOL, HVACMode.AUTO]

def _update_internal_state(self):
"""c"""
self._attr_available = self.is_available()
self._attr_is_on = self.is_follow_me()

# i have no idea why, but call to turn on and off the light is inverted on the cielo app
# class CieloHomeSwitchLight(CieloHomeEntity, SwitchEntity):
Expand Down