Forráskód Böngészése

Summary: tests (datetime): add tests for shifted datetime, fix issues

Issue #4466
Jason Rumney 6 napja
szülő
commit
13cb9f0089

+ 3 - 3
custom_components/tuya_local/datetime.py

@@ -89,17 +89,17 @@ class TuyaLocalDateTime(TuyaLocalEntity, DateTimeEntity):
             return None
         year = year or 1970
         month = month or 1
-        days = day or 1
+        days = (day or 1) - 1
         hours = hours or 0
         minutes = minutes or 0
         seconds = seconds or 0
         delta = timedelta(
-            days=int(days) - 1,
+            days=int(days),
             hours=int(hours),
             minutes=int(minutes),
             seconds=int(seconds),
         )
-        return (datetime(year=year, month=month, day=1, tzinfo=tz) + delta).datetime()
+        return datetime(year=year, month=month, day=1, tzinfo=tz) + delta
 
     async def async_set_value(self, value: datetime):
         """Set the datetime."""

+ 2 - 2
custom_components/tuya_local/devices/elko_cfmtb_thermostat.yaml

@@ -265,8 +265,8 @@ entities:
         mapping:
           # device uses 1/1/2000 epoch, so shift it
           - target_range:
-              min: 1577750400
-              max: 3725234047
+              min: 946684800
+              max: 3094168447
   - entity: number
     name: Heating temperature
     class: temperature

+ 37 - 0
tests/const.py

@@ -1707,3 +1707,40 @@ AILRINNI_FINGERPRINTLOCK_PAYLOAD = {
     "31": "mute",
     "64": "1712614183",
 }
+
+ELKO_CFMTB_THERMOSTAT_PAYLOAD = {
+    "101": "02.01.01.68",
+    "102": "02.02.15.6D",
+    "103": 1000,
+    "104": 1750,
+    "105": 2200,
+    "107": 2200,
+    "108": 0,
+    "109": 2200,
+    "110": 2200,
+    "111": 200,
+    "112": 200,
+    "113": 1800,
+    "114": 2400,
+    "115": False,
+    "116": False,
+    "117": False,
+    "118": 8,
+    "121": "Heat",
+    "122": "Unoccupied",
+    "123": "Close",
+    "128": 0,
+    "129": "10K",
+    "130": -300,
+    "131": False,
+    "132": 100,
+    "133": 0,
+    "134": 60,
+    "139": "NotConnected",
+    "140": "Manual",
+    "145": "EKO07262;B;16A",
+    "146": False,
+    "150": 0,
+    "151": 773999,
+    "152": True,
+}

+ 67 - 0
tests/devices/test_elko_cfmtb_thermostat.py

@@ -0,0 +1,67 @@
+from datetime import datetime, timezone
+
+from ..const import ELKO_CFMTB_THERMOSTAT_PAYLOAD
+from ..helpers import assert_device_properties_set
+from .base_device_tests import TuyaDeviceTestCase
+
+OVERRIDE_END_DPS = "108"
+
+
+class TestElkoCFMTBThermostat(TuyaDeviceTestCase):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig(
+            "elko_cfmtb_thermostat.yaml",
+            ELKO_CFMTB_THERMOSTAT_PAYLOAD,
+        )
+        self.subject = self.entities.get("datetime_override_end")
+        self.mark_secondary(
+            [
+                "number_power_rating",
+                "lock_child_lock",
+                "number_active_screen_brightness",
+                "number_standby_screen_brightness",
+                "sensor_external_sensor_type",
+                "sensor_device_type",
+                "sensor_floor_temperature",
+                "sensor_air_temperature",
+                "sensor_power",
+                "sensor_energy",
+                "datetime_override_end",
+                "number_heating_temperature",
+                "number_cooling_temperature",
+                "number_away_heating_reduction",
+                "number_away_cooling_reduction",
+                "number_away_minimum_temperature",
+                "number_away_maximum_temperature",
+                "switch_away",
+                "switch_schedule",
+                "binary_sensor_occupancy",
+                "binary_sensor_window",
+                "number_room_temperature_calibration",
+                "number_external_temperature_calibration",
+                "number_screen_timeout",
+                "switch_screen_timeout",
+                "switch_regulator_mode",
+            ]
+        )
+
+    def test_datetime_override_end(self):
+        self.dps[OVERRIDE_END_DPS] = (
+            1770465243 - datetime(2000, 1, 1, tzinfo=timezone.utc).timestamp()
+        )
+        self.assertEqual(
+            self.subject.native_value,
+            datetime(2026, 2, 7, 11, 54, 3, tzinfo=timezone.utc),
+        )
+
+    async def test_set_datetime_override_end(self):
+        MILLINIUM = datetime(2000, 1, 1, tzinfo=timezone.utc).timestamp()
+        async with assert_device_properties_set(
+            self.subject._device,
+            {OVERRIDE_END_DPS: 1770465243 - MILLINIUM},
+        ):
+            await self.subject.async_set_value(
+                datetime(2026, 2, 7, 11, 54, 3, tzinfo=timezone.utc)
+            )