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

fix(e2): input target_temperature should be float #358

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
22 changes: 20 additions & 2 deletions midealocal/devices/e2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,16 @@ def __init__(
)
self._default_old_protocol = OldProtocol.auto
self._old_protocol = self._default_old_protocol
# target_temperature step
self._temperature_step: float | None = None
self._default_temperature_step = 1
self.set_customize(customize)

@property
def temperature_step(self) -> float | None:
"""Midea E3 device target temperature step."""
return self._temperature_step

def _normalize_old_protocol(self, value: str | bool | int) -> OldProtocol:
if isinstance(value, str):
return_value = OldProtocol(value)
Expand Down Expand Up @@ -139,7 +147,7 @@ def make_message_set(self) -> MessageSet:
message.variable_heating = self._attributes[DeviceAttributes.variable_heating]
return message

def set_attribute(self, attr: str, value: bool | int | str) -> None:
def set_attribute(self, attr: str, value: bool | float | str) -> None:
"""Midea E2 device set attribute."""
message: MessagePower | MessageSet | MessageNewProtocolSet | None = None
if attr not in [
Expand All @@ -148,6 +156,9 @@ def set_attribute(self, attr: str, value: bool | int | str) -> None:
DeviceAttributes.current_temperature,
]:
old_protocol = self._normalize_old_protocol(self._old_protocol)
# convert input float target_temperature to int for message byte
if attr == DeviceAttributes.target_temperature:
value = int(value * 2)
if attr == DeviceAttributes.power:
message = MessagePower(self._message_protocol_version)
message.power = bool(value)
Expand All @@ -169,9 +180,16 @@ def set_customize(self, customize: str) -> None:
self._old_protocol = self._normalize_old_protocol(
params["old_protocol"],
)
if params and "temperature_step" in params:
self._temperature_step = params.get("temperature_step")
except Exception:
_LOGGER.exception("[%s] Set customize error", self.device_id)
self.update_all({"old_protocol": self._old_protocol})
self.update_all(
{
"temperature_step": self._temperature_step,
"old_protocol": self._old_protocol,
},
)


class MideaAppliance(MideaE2Device):
Expand Down