Skip to content

Commit

Permalink
Extend climate support (#15)
Browse files Browse the repository at this point in the history
- Climate: added support for humidity and target_humidity
- Added data dictionary and translation strings for 009-109
  • Loading branch information
oyvindwe authored Jul 7, 2024
1 parent 3c3d253 commit 068e84d
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ visibility.

| Device name | Device type | Device type code | Device feature code | Data dictionary |
|--------------|-----------------|------------------|---------------------|-------------------------------------------------------------------------------------------|
| W-DW50/60-22 | Dishwasher | 015 | 000 | [Most properties completed](custom_components/connectlife/data_dictionaries/015-000.yaml) |
| | Dehumidifier | 007 | 400 | [Completed, but untested](custom_components/connectlife/data_dictionaries/007-400.yaml) |
| | Air conditioner | 009 | 109 | [In progress](custom_components/connectlife/data_dictionaries/009-109.yaml) |
| W-DW50/60-22 | Dishwasher | 015 | 000 | [Most properties completed](custom_components/connectlife/data_dictionaries/015-000.yaml) |

Please, please, please contribute PRs with [data dictionaries](custom_components/connectlife/data_dictionaries) for your devices!

Expand Down
27 changes: 19 additions & 8 deletions custom_components/connectlife/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
HVAC_ACTION,
IS_ON,
SWING_MODE,
TARGET_HUMIDITY,
TARGET_TEMPERATURE,
TEMPERATURE_UNIT,
)
Expand Down Expand Up @@ -60,8 +61,6 @@ class ConnectLifeClimate(ConnectLifeEntity, ClimateEntity):
_attr_target_temperature_step = 1
_attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_hvac_mode = None
_attr_fan_mode = None
_attr_swing_mode = None
target_map = {}
fan_mode_map: dict[int, str] = {}
fan_mode_reverse_map: dict[str, int] = {}
Expand Down Expand Up @@ -96,26 +95,31 @@ def __init__(
self._attr_supported_features |= ClimateEntityFeature.TURN_OFF
self._attr_supported_features |= ClimateEntityFeature.TURN_ON
hvac_modes.append(HVACMode.OFF)
if target == TARGET_TEMPERATURE:
elif target == TARGET_HUMIDITY:
self._attr_supported_features |= ClimateEntityFeature.TARGET_HUMIDITY
self._attr_target_humidity = None
elif target == TARGET_TEMPERATURE:
self._attr_supported_features |= ClimateEntityFeature.TARGET_TEMPERATURE
if target == TEMPERATURE_UNIT:
self._attr_target_temperature = None
elif target == TEMPERATURE_UNIT:
for k, v in data_dictionary[status].climate.options.items():
if v == "celsius" or v == "C":
self.temperature_unit_map[k] = UnitOfTemperature.CELSIUS
elif v == "fahrenheit" or v == "F":
self.temperature_unit_map[k] = UnitOfTemperature.FAHRENHEIT
if target == FAN_MODE:
elif target == FAN_MODE:
self.fan_mode_map = data_dictionary[status].climate.options
self.fan_mode_reverse_map = {v: k for k, v in self.fan_mode_map.items()}
self._attr_fan_modes = list(self.fan_mode_map.values())
self._attr_supported_features |= ClimateEntityFeature.FAN_MODE
if target == SWING_MODE:
self._attr_fan_mode = None
elif target == SWING_MODE:
self.swing_mode_map = data_dictionary[status].climate.options
self.swing_mode_reverse_map = {v: k for k, v in self.swing_mode_map.items()}
self._attr_swing_modes = list(self.swing_mode_map.values())
self._attr_supported_features |= ClimateEntityFeature.SWING_MODE
if target == HVAC_ACTION:
# values = set(item.value for item in Fruit)
self._attr_swing_mode = None
elif target == HVAC_ACTION:
actions = set(action.value for action in HVACAction)
for (k, v) in data_dictionary[status].climate.options.items():
if v in actions:
Expand Down Expand Up @@ -165,6 +169,13 @@ def update_state(self) -> None:
setattr(self, f"_attr_{target}", value)
self._attr_available = self.coordinator.appliances[self.device_id]._offline_state == 1

async def async_set_humidity(self, humidity):
"""Set new target humidity."""
humidity = round(humidity)
await self.coordinator.api.update_appliance(self.puid, {self.target_map[TARGET_HUMIDITY]: humidity})
self._attr_target_humidity = humidity
self.async_write_ha_state()

async def async_set_temperature(self, **kwargs) -> None:
"""Set new target temperature."""
if ATTR_TEMPERATURE in kwargs and TARGET_TEMPERATURE in self.target_map:
Expand Down
1 change: 1 addition & 0 deletions custom_components/connectlife/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
FAN_MODE = "fan_mode"
IS_ON = "is_on"
SWING_MODE = "swing_mode"
TARGET_HUMIDITY = "target_humidity"
TARGET_TEMPERATURE = "target_temperature"
TEMPERATURE_UNIT = "temperature_unit"
51 changes: 51 additions & 0 deletions custom_components/connectlife/data_dictionaries/007-400.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
device_type: dehumidifier
properties:
- property: daily_energy_kwh
hide: true
sensor:
state_class: total
device_class: energy
unit: kWh
- property: f_e_filterclean
binary_sensor:
device_class: problem
- property: f_e_pump
binary_sensor:
device_class: problem
- property: f_e_push
binary_sensor:
device_class: problem
- property: f_e_temp
binary_sensor:
device_class: problem
- property: f_e_tubetemp
binary_sensor:
device_class: problem
- property: f_e_waterfull
binary_sensor:
device_class: problem
- property: f_e_wetsensor
binary_sensor:
device_class: problem
- property: f_humidity
climate:
target: current_humidity
- property: t_fan_speed
climate:
target: fan_mode
options:
0: low
1: high
2: auto
- property: t_humidity
climate:
target: target_humidity
- property: t_power
climate:
target: is_on
- property: t_work_mode
select:
options:
0: continuous
1: manual
2: auto
4 changes: 3 additions & 1 deletion custom_components/connectlife/data_dictionaries/009-109.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ properties:
7: medium
8: middle_high
9: high
- property: t_humidity
- property: f_humidity
climate:
target: current_humidity
- property: t_power
climate:
target: is_on
Expand Down
11 changes: 11 additions & 0 deletions custom_components/connectlife/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"Alarm_door_opened": {
"name": "Door open"
},
"daily_energy_kwh": {
"name": "Daily energy consumption"
},
"Door_status": {
"name": "Door",
"state": {
Expand Down Expand Up @@ -85,6 +88,14 @@
}
},
"select": {
"t_work_mode": {
"name": "Work mode",
"state": {
"auto": "Auto",
"continuous": "Continuous",
"manual": "Manual"
}
},
"t_swing_angle": {
"name": "Swing angle",
"state": {
Expand Down
11 changes: 11 additions & 0 deletions custom_components/connectlife/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
"Alarm_door_opened": {
"name": "Door open"
},
"daily_energy_kwh": {
"name": "Daily energy consumption"
},
"Door_status": {
"name": "Door",
"state": {
Expand Down Expand Up @@ -86,6 +89,14 @@
}
},
"select": {
"t_work_mode": {
"name": "Work mode",
"state": {
"auto": "Auto",
"continuous": "Continuous",
"manual": "Manual"
}
},
"t_swing_angle": {
"name": "Swing angle",
"state": {
Expand Down

0 comments on commit 068e84d

Please sign in to comment.