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

feat(40): add precision_halves customization #248

Merged
merged 3 commits into from
Jul 28, 2024
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
28 changes: 27 additions & 1 deletion midealocal/devices/x40/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Midea local x40 device."""

import json
import logging
import math
from enum import StrEnum
Expand Down Expand Up @@ -43,7 +44,7 @@ def __init__(
protocol: int,
model: str,
subtype: int,
customize: str, # noqa: ARG002
customize: str,
) -> None:
"""Initialize Midea x40 Device."""
super().__init__(
Expand All @@ -67,6 +68,14 @@ def __init__(
},
)
self._fields: dict[str, Any] = {}
self._precision_halves: bool | None = None
self._default_precision_halves = False
self.set_customize(customize)

@property
def precision_halves(self) -> bool | None:
"""Midea 40 device precision halves."""
return self._precision_halves

@property
def directions(self) -> list[str]:
Expand Down Expand Up @@ -100,6 +109,11 @@ def process_message(self, msg: bytes) -> dict[str, Any]:
for status in self._attributes:
if hasattr(message, str(status)):
value = getattr(message, str(status))
if (
self._precision_halves
and status == DeviceAttributes.current_temperature
):
value /= 2
if status == DeviceAttributes.direction:
self._attributes[status] = self._directions[
self._convert_from_midea_direction(value)
Expand Down Expand Up @@ -139,6 +153,18 @@ def set_attribute(self, attr: str, value: int | str | bool) -> None:
setattr(message, str(attr), value)
self.build_send(message)

def set_customize(self, customize: str) -> None:
"""Midea 40 device set customize."""
self._precision_halves = self._default_precision_halves
if customize and len(customize) > 0:
try:
params = json.loads(customize)
if params and "precision_halves" in params:
self._precision_halves = params.get("precision_halves")
except Exception:
_LOGGER.exception("[%s] Set customize error", self.device_id)
self.update_all({"precision_halves": self._precision_halves})


class MideaAppliance(MideaX40Device):
"""Midea x40 appliance."""
Loading