Skip to content

Commit

Permalink
Tumble Dryer - Add Cycle State (#32)
Browse files Browse the repository at this point in the history
* Add tumble dryer support and it translation

* Add it.json translate

* Remove TODO

* fix ambiguous clean_filter var

* fix ambiguous water_tank var

* fix ambiguous door_state var

* Added new attributes

* Fix attributes test value

* New DryerProgramState found

* d

* d

* Copy branch

* Revert "Fix attributes test value"

This reverts commit adc2e36.

* copy branch

* New DryerProgramState

* rebase

* Fix

* Delete files

* New DryerProgramState

* add test file

* Fix typo

* Merge

* Add Dryer Cycle Level

* Type and others fix

* Fix to pass test

* Add Dry level it translation

* Typo fix
  • Loading branch information
terminet85 authored Oct 29, 2021
1 parent 715cc38 commit e82dd7d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
24 changes: 24 additions & 0 deletions custom_components/candy/client/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,33 @@ def __str__(self):
return "%s" % self


class DryerCycleState(Enum):
LEVEL_NONE = 0
LEVEL_IRON = 1
LEVEL_HANG = 2
LEVEL_STORE = 3
LEVEL_BONE = 4

def __str__(self):
if self == DryerCycleState.LEVEL_NONE:
return "No Dry"
elif self == DryerCycleState.LEVEL_IRON:
return "Iron Dry"
elif self == DryerCycleState.LEVEL_HANG:
return "Hang Dry"
elif self == DryerCycleState.LEVEL_STORE:
return "Store Dry"
elif self == DryerCycleState.LEVEL_BONE:
return "Bone Dry"
else:
return "%s" % self


@dataclass
class TumbleDryerStatus:
machine_state: MachineState
program_state: DryerProgramState
cycle_state: DryerCycleState
program: int
remaining_minutes: int
remote_control: bool
Expand All @@ -132,6 +155,7 @@ def from_json(cls, json):
return cls(
machine_state=MachineState(int(json["StatoTD"])),
program_state=DryerProgramState(int(json["PrPh"])),
cycle_state=DryerCycleState(int(json["DryLev"])),
program=int(json["Pr"]),
remaining_minutes=int(json["RemTime"]),
remote_control=json["StatoWiFi"] == "1",
Expand Down
7 changes: 5 additions & 2 deletions custom_components/candy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from homeassistant.helpers.typing import StateType
from .client import WashingMachineStatus
from .client.model import MachineState, TumbleDryerStatus, OvenStatus, DishwasherStatus, DishwasherState
from .client.model import MachineState, TumbleDryerStatus, DryerProgramState, OvenStatus, DishwasherStatus, DishwasherState
from .const import *
from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -234,7 +234,10 @@ def unique_id(self) -> str:
@property
def state(self) -> StateType:
status: TumbleDryerStatus = self.coordinator.data
return str(status.program_state)
if status.program_state in [DryerProgramState.STOPPED]:
return str(status.cycle_state)
else:
return str(status.program_state)

@property
def icon(self) -> str:
Expand Down
7 changes: 6 additions & 1 deletion custom_components/candy/translations/sensor.it.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
"Steam": "In vapore",
"Spin - Good Night": "In centrifuga - Modalità Notte",
"Spin": "In centrifuga",
"Heating": "Sto riscaldando"
"Heating": "Sto riscaldando",
"No Dry": "No asciugatura",
"Iron Dry": "Pronto Stiro",
"Hang Dry": "Asciutto No Stiro",
"Store Dry": "Asciutto Armadio",
"Bone Dry": "Extra Asciutto"
}
}
}
2 changes: 1 addition & 1 deletion tests/test_sensor_tumble_dryer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def test_cycle_sensor_idle(hass: HomeAssistant, aioclient_mock: AiohttpCli
state = hass.states.get("sensor.dryer_cycle_status")

assert state
assert state.state == "Stopped"
assert state.state == "Hang Dry"
assert state.attributes == {
"friendly_name": "Dryer cycle status",
"icon": "mdi:tumble-dryer"
Expand Down

0 comments on commit e82dd7d

Please sign in to comment.