Skip to content

Commit

Permalink
feat(40): add precision_halves customization
Browse files Browse the repository at this point in the history
  • Loading branch information
Necroneco committed Jul 26, 2024
1 parent 536f975 commit 525c4ed
Showing 1 changed file with 27 additions and 1 deletion.
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."""

0 comments on commit 525c4ed

Please sign in to comment.