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

Adjust Atlantic Electrical Heater to new standards and fix issues #454

Merged
merged 5 commits into from
Jul 14, 2021
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@

COMMAND_SET_HEATING_LEVEL = "setHeatingLevel"

CORE_ON_OFF_STATE = "core:OnOffState"
IO_TARGET_HEATING_LEVEL_STATE = "io:TargetHeatingLevelState"

PRESET_FREEZE = "Freeze"
PRESET_FROST_PROTECTION = "frostprotection"
PRESET_OFF = "off"
PRESET_FREEZE = "freeze"
iMicknl marked this conversation as resolved.
Show resolved Hide resolved

MAP_PRESET_MODES = {
PRESET_OFF: PRESET_NONE,
PRESET_FROST_PROTECTION: PRESET_FREEZE,
PRESET_ECO: PRESET_ECO,
PRESET_COMFORT: PRESET_COMFORT,
TAHOMA_TO_PRESET_MODES = {
"off": PRESET_NONE,
"frostprotection": PRESET_FREEZE,
"eco": PRESET_ECO,
"comfort": PRESET_COMFORT,
}

MAP_REVERSE_PRESET_MODES = {v: k for k, v in MAP_PRESET_MODES.items()}
PRESET_MODES_TO_TAHOMA = {v: k for k, v in TAHOMA_TO_PRESET_MODES.items()}

MAP_HVAC_MODES = {HVAC_MODE_HEAT: PRESET_COMFORT, HVAC_MODE_OFF: PRESET_OFF}
TAHOMA_TO_HVAC_MODES = {"on": HVAC_MODE_HEAT, "off": HVAC_MODE_OFF}
HVAC_MODES_TO_TAHOMA = {v: k for k, v in TAHOMA_TO_HVAC_MODES.items()}


class AtlanticElectricalHeater(TahomaEntity, ClimateEntity):
Expand All @@ -52,35 +52,31 @@ def supported_features(self) -> int:
@property
def hvac_mode(self) -> str:
"""Return hvac operation ie. heat, cool mode."""
return HVAC_MODE_OFF if self.preset_mode == PRESET_NONE else HVAC_MODE_HEAT
return TAHOMA_TO_HVAC_MODES[self.select_state(*CORE_ON_OFF_STATE)]

@property
def hvac_modes(self) -> List[str]:
"""Return the list of available hvac operation modes."""
return [*MAP_HVAC_MODES]
return [*HVAC_MODES_TO_TAHOMA]

async def async_set_hvac_mode(self, hvac_mode: str) -> None:
"""Set new target hvac mode."""
await self.async_execute_command(
COMMAND_SET_HEATING_LEVEL, HVAC_MODES_TO_TAHOMA[hvac_mode]
iMicknl marked this conversation as resolved.
Show resolved Hide resolved
)

@property
def preset_mode(self) -> Optional[str]:
"""Return the current preset mode, e.g., home, away, temp."""
return MAP_PRESET_MODES[self.select_state(IO_TARGET_HEATING_LEVEL_STATE)]
return TAHOMA_TO_PRESET_MODES[self.select_state(IO_TARGET_HEATING_LEVEL_STATE)]

@property
def preset_modes(self) -> Optional[List[str]]:
"""Return a list of available preset modes."""
return [PRESET_NONE, PRESET_FREEZE, PRESET_ECO, PRESET_COMFORT]

async def async_set_hvac_mode(self, hvac_mode: str) -> None:
"""Set new target hvac mode."""
await self.async_execute_command(
COMMAND_SET_HEATING_LEVEL, MAP_HVAC_MODES[hvac_mode]
)
return [*PRESET_MODES_TO_TAHOMA]

async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
await self.async_execute_command(
COMMAND_SET_HEATING_LEVEL, MAP_REVERSE_PRESET_MODES[preset_mode]
COMMAND_SET_HEATING_LEVEL, PRESET_MODES_TO_TAHOMA[preset_mode]
)

async def async_turn_off(self) -> None:
"""Turn off the device."""
await self.async_execute_command(COMMAND_SET_HEATING_LEVEL, PRESET_OFF)