Skip to content

Commit

Permalink
various fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bodyscape committed Jul 24, 2024
1 parent c1ac4fc commit 77d12cf
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 50 deletions.
76 changes: 55 additions & 21 deletions custom_components/cielo_home/cielohomedevice.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The Cielo Home integration."""

import asyncio
import contextlib
import logging
Expand Down Expand Up @@ -98,26 +99,55 @@ def _send_power(self, value) -> None:
self._device["latestAction"]["power"] = value
self._send_msg(action, "power", action["power"])

def sync_ac_state(
self, power: bool, temp: int, mode: str, fan_speed: str, swing: str
) -> None:
"""None."""
action = {
"power": "on" if power else "off",
"temp": temp
if power and temp > 0
else self._device["latestAction"]["temp"],
"mode": mode
if power and mode != ""
else self._device["latestAction"]["mode"],
"fanspeed": fan_speed
if power and fan_speed != ""
else self._device["latestAction"]["fanspeed"],
"swing": swing
if power and swing != ""
else self._device["latestAction"]["swing"],
}
self._send_msg(action, "", "", default_action="syncState")
# def sync_ac_state_test(
# self, power: bool, temp: int, mode: str, fan_speed: str, swing: str, preset: str
# ) -> None:
# """None."""
# action = self._get_action()
# action["power"] = "on" if power else "off"
#
# if power:
# if temp > 0:
# action["temp"] = temp
#
# if mode != "":
# action["mode"] = mode
#
# if fan_speed != "":
# action["fanspeed"] = fan_speed
#
# if swing != "":
# action["swing"] = swing
#
# if preset != "":
# action["preset"] = preset
#
# self._send_msg(action, "", "", default_action="actionControl")

# def sync_ac_state(
# self, power: bool, temp: int, mode: str, fan_speed: str, swing: str, preset: str
# ) -> None:
# """None."""
# action = self._get_action()
# action = {
# "power": "on" if power else "off",
# "temp": temp
# if power and temp > 0
# else self._device["latestAction"]["temp"],
# "mode": mode
# if power and mode != ""
# else self._device["latestAction"]["mode"],
# "fanspeed": fan_speed
# if power and fan_speed != ""
# else self._device["latestAction"]["fanspeed"],
# "swing": swing
# if power and swing != ""
# else self._device["latestAction"]["swing"],
# "preset": preset
# if power and preset != ""
# else self._device["latestAction"]["turbo"],
# }
# self._send_msg(action, "", "", default_action="syncState")

def send_light_on(self) -> None:
"""None."""
Expand Down Expand Up @@ -153,7 +183,11 @@ def _send_turbo(self, value) -> None:
action = self._get_action()
action["turbo"] = value
self._device["latestAction"]["turbo"] = value
self._send_msg(action, "turbo", "on/off")

if self.get_device_type_version() != "BI03":
value = "on/off"

self._send_msg(action, "turbo", value)

def _send_msg(
self, action, action_type, action_value, default_action="actionControl"
Expand Down
59 changes: 32 additions & 27 deletions custom_components/cielo_home/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
FAN_HIGH_VALUE,
FAN_LOW_VALUE,
FAN_MEDIUM_VALUE,
PRESET_NONE,
PRESET_TURBO,
SWING_ADJUST_VALUE,
SWING_AUTO_STOP_VALUE,
SWING_AUTO_VALUE,
Expand Down Expand Up @@ -54,6 +56,7 @@ async def async_setup_entry(
platform = entity_platform.async_get_current_platform()

list_fan_speed = [FAN_AUTO_VALUE, FAN_LOW_VALUE, FAN_MEDIUM_VALUE, FAN_HIGH_VALUE]
list_preset_mode = [PRESET_NONE, PRESET_TURBO]
list_swing = [
SWING_AUTO_VALUE,
SWING_ADJUST_VALUE,
Expand All @@ -65,17 +68,20 @@ async def async_setup_entry(
SWING_POSITION5_VALUE,
SWING_POSITION6_VALUE,
]
platform.async_register_entity_service(
"sync_ac_state",
{
vol.Required("power", default=False): cv.boolean,
vol.Optional("temp"): vol.Coerce(int),
vol.Optional("mode"): vol.All(vol.In(HVAC_MODES)),
vol.Optional("fan_speed"): vol.All(vol.In(list_fan_speed)),
vol.Optional("swing"): vol.All(vol.In(list_swing)),
},
"async_sync_ac_state",
)


# platform.async_register_entity_service(
# "sync_ac_state",
# {
# vol.Required("power", default=False): cv.boolean,
# vol.Optional("temp"): vol.Coerce(int),
# vol.Optional("mode"): vol.All(vol.In(HVAC_MODES)),
# vol.Optional("fan_speed"): vol.All(vol.In(list_fan_speed)),
# vol.Optional("swing"): vol.All(vol.In(list_swing)),
# vol.Optional("preset"): vol.All(vol.In(list_preset_mode)),
# },
# "async_sync_ac_state",
# )


class CieloHomeThermostat(CieloHomeEntity, ClimateEntity):
Expand All @@ -85,14 +91,12 @@ def __init__(self, device: CieloHomeDevice) -> None:
"""Initialize the thermostat."""
super().__init__(device, device.get_name(), device.get_uniqueid())
self._attr_target_temperature_step = int(self._device.get_temp_increment())
self._attr_supported_features = (
self._attr_supported_features
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
)

self._attr_supported_features |= ClimateEntityFeature.TURN_OFF
self._attr_supported_features |= ClimateEntityFeature.TURN_ON

if self._device.get_supportTargetTemp():
self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
self._attr_supported_features |= ClimateEntityFeature.TARGET_TEMPERATURE
self._attr_temperature_unit = self._device.get_unit_of_temperature()

self._attr_hvac_modes = self._device.get_hvac_modes()
Expand Down Expand Up @@ -152,16 +156,17 @@ def set_temperature(self, **kwargs: Any) -> None:

self._update_internal_state()

async def async_sync_ac_state(
self,
power: bool,
temp: int = 0,
mode: str = "",
fan_speed: str = "",
swing: str = "",
) -> None:
"""Sync_ac_state."""
self._device.sync_ac_state(power, temp, mode, fan_speed, swing)
# async def async_sync_ac_state(
# self,
# power: bool,
# temp: int = 0,
# mode: str = "",
# fan_speed: str = "",
# swing: str = "",
# preset: str = "",
# ) -> None:
# """Sync_ac_state."""
# self._device.sync_ac_state(power, temp, mode, fan_speed, swing, preset)

def set_swing_mode(self, swing_mode: str) -> None:
"""Set new target swing operation."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/cielo_home/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Constants for the Cielo Home integration."""

from homeassistant.components.climate import PRESET_NONE

DOMAIN = "cielo_home"
Expand Down Expand Up @@ -28,7 +29,6 @@
SWING_POSITION5_VALUE = "pos5"
SWING_POSITION6_VALUE = "pos6"

PRESET_NONE = "none"
PRESET_TURBO = "Turbo"
PRESET_MODES = [PRESET_NONE, PRESET_TURBO]

Expand Down
2 changes: 1 addition & 1 deletion custom_components/cielo_home/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "cloud_push",
"issue_tracker": "https://github.com/bodyscape/cielo_home/issues",
"requirements": [],
"version": "1.7.6"
"version": "1.7.7"
}
19 changes: 19 additions & 0 deletions custom_components/cielo_home/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,22 @@ sync_ac_state:
- "pos4"
- "pos5"
- "pos6"
preset:
# Field name as shown in UI
name: Preset mode
# Description of the field
description: Preset mode setting
# Whether or not field is required (default = false)
required: false
# Advanced fields are only shown when the advanced mode is enabled for the user (default = false)
advanced: false
# Example value that can be passed for this field
example: "none"
# The default field value
default: "none"
# Selector (https://www.home-assistant.io/docs/blueprint/selectors/) to control the input UI for this field
selector:
select:
options:
- "none"
- "Turbo"
Empty file.

0 comments on commit 77d12cf

Please sign in to comment.