Ver Fonte

feat: add Meter Pro display and calibration settings (#621)

* feat: add Meter Pro display and calibration settings

Add calibration, display zones and icons, data update interval, date
format, battery icon, default temperature unit and button functions to
SwitchbotMeterPro, so both the Meter Pro and Meter Pro CO2 get them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(meter-pro): handle unknown display and button settings

* fix(meter-pro): validate display interval and calibration values

* docs(meter-pro): clarify button flags and factory settings test

---------

Co-authored-by: Benoit Vuillemin <6716106+bvuillemin@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zerzhang <916250497@qq.com>
Benoit Vuillemin há 2 dias atrás
pai
commit
b6371bcd40

+ 8 - 0
switchbot/__init__.py

@@ -24,7 +24,11 @@ from .const import (
     HumidifierMode,
     HumidifierWaterLevel,
     LockStatus,
+    MeterProDateFormat,
+    MeterProDisplaySource,
+    MeterProDisplayZone,
     MeterProWeatherIcon,
+    MeterProZoneIcon,
     NightLightState,
     QuickKeyFunction,
     SmartThermostatRadiatorMode,
@@ -111,7 +115,11 @@ __all__ = [
     "HumidifierMode",
     "HumidifierWaterLevel",
     "LockStatus",
+    "MeterProDateFormat",
+    "MeterProDisplaySource",
+    "MeterProDisplayZone",
     "MeterProWeatherIcon",
+    "MeterProZoneIcon",
     "NightLightState",
     "QuickKeyFunction",
     "SmartThermostatRadiatorMode",

+ 11 - 1
switchbot/const/__init__.py

@@ -27,7 +27,13 @@ from .light import (
 
 # Preserve old LockStatus export for backwards compatibility
 from .lock import LockStatus, QuickKeyFunction
-from .meter_pro import MeterProWeatherIcon
+from .meter_pro import (
+    MeterProDateFormat,
+    MeterProDisplaySource,
+    MeterProDisplayZone,
+    MeterProWeatherIcon,
+    MeterProZoneIcon,
+)
 
 DEFAULT_RETRY_COUNT = 3
 DEFAULT_RETRY_TIMEOUT = 1
@@ -167,7 +173,11 @@ __all__ = [
     "HumidifierMode",
     "HumidifierWaterLevel",
     "LockStatus",
+    "MeterProDateFormat",
+    "MeterProDisplaySource",
+    "MeterProDisplayZone",
     "MeterProWeatherIcon",
+    "MeterProZoneIcon",
     "NightLightState",
     "QuickKeyFunction",
     "SmartThermostatRadiatorMode",

+ 35 - 0
switchbot/const/meter_pro.py

@@ -12,3 +12,38 @@ class MeterProWeatherIcon(Enum):
     HEAVY_RAIN = 5
     LIGHT_SNOW = 6
     HEAVY_SNOW = 7
+
+
+class MeterProDisplayZone(Enum):
+    """Configurable areas of the Meter Pro screen."""
+
+    MIDDLE = 1
+    BOTTOM = 2
+
+
+class MeterProZoneIcon(Enum):
+    """Icon shown next to a display zone."""
+
+    INDOOR = 1
+    OUTDOOR = 2
+
+
+class MeterProDisplaySource(Enum):
+    """Where a display zone takes its temperature and humidity from."""
+
+    NONE = 0
+    METER = 1
+    METER_PLUS = 2
+    INDOOR_OUTDOOR_METER = 3
+    HUB = 4  # Hub 2 and Hub Mini Matter
+    METER_PRO = 5  # this device when the MAC is empty, else another Meter Pro
+    NETWORK = 6  # values written with the weather command
+    WEATHER_STATION = 8
+    HUB3 = 9
+
+
+class MeterProDateFormat(Enum):
+    """Date layout on the screen."""
+
+    MONTH_DAY = 0
+    DAY_MONTH = 1

+ 239 - 1
switchbot/devices/meter_pro.py

@@ -1,7 +1,13 @@
 from decimal import ROUND_HALF_UP, Decimal
 from typing import Any
 
-from ..const.meter_pro import MeterProWeatherIcon
+from ..const.meter_pro import (
+    MeterProDateFormat,
+    MeterProDisplaySource,
+    MeterProDisplayZone,
+    MeterProWeatherIcon,
+    MeterProZoneIcon,
+)
 from ..helpers import parse_uint24_be
 from .device import SwitchbotDevice, SwitchbotOperationError
 
@@ -12,6 +18,27 @@ MAX_TIME_OFFSET = (1 << 24) - 1
 COMMAND_GET_DEVICE_DATETIME = "570f6901"
 COMMAND_SET_DEVICE_DATETIME = "57000503"
 COMMAND_SET_DISPLAY_FORMAT = "570f680505"
+
+COMMAND_GET_CALIBRATION = "570f6903"
+COMMAND_SET_CALIBRATION = "570f6803"
+COMMAND_GET_DISPLAY_SETTINGS = "570f690701"
+COMMAND_SET_DISPLAY_ZONE = "570f680701"
+COMMAND_SET_ZONE_ICONS = "570f68070103"
+COMMAND_SET_DATA_UPDATE_INTERVAL = "570f68070105"
+COMMAND_GET_BUTTON_FUNCTIONS = "570f690704"
+COMMAND_SET_BUTTON_FUNCTIONS = "570f68070106"
+COMMAND_SET_DATE_FORMAT = "570f68070107"
+COMMAND_SET_BATTERY_ICON = "570f68070108"
+COMMAND_SET_TEMPERATURE_UNIT = "570f68070109"
+
+MAX_HUMIDITY_CALIBRATION = 99
+MAX_DATA_UPDATE_INTERVAL = 0xFFFF
+NO_MAC = "000000000000"
+# "Keep current value" differs between the single-zone and two-icon commands.
+KEEP_ZONE_ICON = 0xFF
+KEEP_ICON = 0x0F
+KEEP_BUTTON_FUNCTION = 0xFF
+SOURCES_WITHOUT_MAC = {MeterProDisplaySource.NONE, MeterProDisplaySource.NETWORK}
 COMMAND_GET_WEATHER = "570f6906"
 COMMAND_SET_WEATHER = "570f680601"
 
@@ -61,6 +88,23 @@ def _encode_weather_icon(icon: MeterProWeatherIcon | int) -> MeterProWeatherIcon
     return MeterProWeatherIcon(icon)
 
 
+def _mac_hex(mac: str | None) -> str:
+    """Return a MAC address as 12 hex digits, all zeros when empty."""
+    if not mac:
+        return NO_MAC
+    cleaned = mac.replace(":", "").replace("-", "").lower()
+    if len(cleaned) != 12 or any(c not in "0123456789abcdef" for c in cleaned):
+        raise ValueError(f"Invalid MAC address {mac!r}")
+    return cleaned
+
+
+def _format_mac(raw: bytes) -> str | None:
+    """Return "AA:BB:CC:DD:EE:FF", or None for an empty MAC."""
+    if not any(raw):
+        return None
+    return ":".join(f"{b:02X}" for b in raw)
+
+
 class SwitchbotMeterPro(SwitchbotDevice):
     """Implement the shared protocol for SwitchBot Meter Pro and Meter Pro CO2."""
 
@@ -206,6 +250,200 @@ class SwitchbotMeterPro(SwitchbotDevice):
         result = await self._send_command(payload)
         self._validate_result("set_time_display_format", result)
 
+    async def get_calibration(self) -> dict[str, Any]:
+        """Get the temperature (C) and humidity (%RH) corrections."""
+        # [status][temp sign|int][hum sign|value][temp tenths]; sign bit = positive
+        result = await self._send_command(COMMAND_GET_CALIBRATION)
+        result = self._validate_result("get_calibration", result, min_length=4)
+        tenths = result[3] & 0x0F
+        humidity = result[2] & 0x7F
+        if tenths > 9 or humidity > MAX_HUMIDITY_CALIBRATION:
+            raise SwitchbotOperationError(
+                f"{self.name}: Invalid calibration response "
+                f"(result={result.hex()} rssi={self.rssi})"
+            )
+        temperature = round((result[1] & 0x7F) + tenths / 10, 1)
+        # A zero correction comes back with the sign bit cleared.
+        return {
+            "temperature": temperature if result[1] & 0x80 else -temperature or 0.0,
+            "humidity": humidity if result[2] & 0x80 else -humidity,
+        }
+
+    async def set_calibration(
+        self, temperature: float | Decimal, humidity: int
+    ) -> None:
+        """Set the temperature (C, rounded half-up to tenths) and humidity corrections."""
+        try:
+            decimal, temperature_byte = _encode_weather_temperature(temperature)
+        except (TypeError, ValueError) as exc:
+            raise SwitchbotOperationError(f"{self.name}: {exc}") from exc
+        if (
+            isinstance(humidity, bool)
+            or not isinstance(humidity, int)
+            or abs(humidity) > MAX_HUMIDITY_CALIBRATION
+        ):
+            raise SwitchbotOperationError(
+                f"{self.name}: Humidity calibration must be an integer within "
+                f"±{MAX_HUMIDITY_CALIBRATION}, got {humidity!r}"
+            )
+        humidity_byte = abs(humidity) | (0x80 if humidity >= 0 else 0)
+        payload = (
+            f"{COMMAND_SET_CALIBRATION}{temperature_byte:02x}"
+            f"{humidity_byte:02x}{decimal:02x}"
+        )
+        result = await self._send_command(payload)
+        self._validate_result("set_calibration", result)
+
+    async def get_display_settings(self) -> dict[str, Any]:
+        """
+        Get the zones, data update interval, date format and battery icon.
+
+        Missing fields and unknown date or battery icon values are None.
+        Each zone has "icon", "source" (the raw int if unknown) and "source_mac"
+        (None when the zone shows this device or network data).
+        """
+        # [status][icons mid|bot][sources mid|bot][mac mid x6][mac bot x6]
+        # [data update interval u16][date format][reserved][battery icon]
+        result = await self._send_command(COMMAND_GET_DISPLAY_SETTINGS)
+        result = self._validate_result("get_display_settings", result, min_length=15)
+
+        def zone(icon: int, source: int, mac: bytes) -> dict[str, Any]:
+            return {
+                "icon": next((i for i in MeterProZoneIcon if i.value == icon), None),
+                "source": next(
+                    (s for s in MeterProDisplaySource if s.value == source), source
+                ),
+                "source_mac": _format_mac(mac),
+            }
+
+        return {
+            "middle": zone(result[1] >> 4, result[2] >> 4, result[3:9]),
+            "bottom": zone(result[1] & 0x0F, result[2] & 0x0F, result[9:15]),
+            "data_update_interval": (
+                int.from_bytes(result[15:17], "big") if len(result) >= 17 else None
+            ),
+            "date_format": (
+                MeterProDateFormat(result[17])
+                if len(result) >= 18 and result[17] in (0x00, 0x01)
+                else None
+            ),
+            "battery_icon_always": (
+                bool(result[19])
+                if len(result) >= 20 and result[19] in (0x00, 0x01)
+                else None
+            ),
+        }
+
+    async def set_display_zone(
+        self,
+        zone: MeterProDisplayZone,
+        source: MeterProDisplaySource,
+        source_mac: str | None = None,
+        icon: MeterProZoneIcon | None = None,
+    ) -> None:
+        """
+        Choose what a screen zone shows; icon None keeps the current icon.
+
+        The device reads the source thermometer over BLE itself. NETWORK shows
+        the values written by set_weather. METER_PRO without a MAC is this
+        device. The screen applies it at the next data update.
+        """
+        try:
+            mac = _mac_hex(source_mac)
+        except ValueError as err:
+            raise SwitchbotOperationError(f"{self.name}: {err}") from err
+        if mac != NO_MAC and source in SOURCES_WITHOUT_MAC:
+            raise SwitchbotOperationError(
+                f"{self.name}: {source.name} display source takes no MAC address"
+            )
+        if mac == NO_MAC and source not in (
+            *SOURCES_WITHOUT_MAC,
+            MeterProDisplaySource.METER_PRO,
+        ):
+            raise SwitchbotOperationError(
+                f"{self.name}: {source.name} display source needs a MAC address"
+            )
+        icon_byte = KEEP_ZONE_ICON if icon is None else icon.value
+        payload = (
+            f"{COMMAND_SET_DISPLAY_ZONE}{zone.value:02x}{icon_byte:02x}"
+            f"{source.value:02x}{mac}"
+        )
+        result = await self._send_command(payload)
+        self._validate_result("set_display_zone", result)
+
+    async def set_zone_icons(
+        self,
+        middle: MeterProZoneIcon | None = None,
+        bottom: MeterProZoneIcon | None = None,
+    ) -> None:
+        """Set the indoor/outdoor icons of both zones; None keeps an icon."""
+        middle_byte = KEEP_ICON if middle is None else middle.value
+        bottom_byte = KEEP_ICON if bottom is None else bottom.value
+        payload = f"{COMMAND_SET_ZONE_ICONS}{middle_byte:02x}{bottom_byte:02x}"
+        result = await self._send_command(payload)
+        self._validate_result("set_zone_icons", result)
+
+    async def set_data_update_interval(self, seconds: int) -> None:
+        """Set the temperature and humidity update interval; the app offers 300, 600 and 1800 s."""
+        if (
+            isinstance(seconds, bool)
+            or not isinstance(seconds, int)
+            or not 1 <= seconds <= MAX_DATA_UPDATE_INTERVAL
+        ):
+            raise SwitchbotOperationError(
+                f"{self.name}: Data update interval must be an integer from "
+                f"1 to {MAX_DATA_UPDATE_INTERVAL} seconds, got {seconds!r}"
+            )
+        payload = COMMAND_SET_DATA_UPDATE_INTERVAL + seconds.to_bytes(2, "big").hex()
+        result = await self._send_command(payload)
+        self._validate_result("set_data_update_interval", result)
+
+    async def set_date_format(self, date_format: MeterProDateFormat) -> None:
+        """Set the date format; the app offers it from firmware 1.5."""
+        payload = f"{COMMAND_SET_DATE_FORMAT}{date_format.value:02x}"
+        result = await self._send_command(payload)
+        self._validate_result("set_date_format", result)
+
+    async def set_battery_icon(self, always: bool) -> None:
+        """Show the battery icon always, or only when the battery is low."""
+        payload = f"{COMMAND_SET_BATTERY_ICON}{'01' if always else '00'}"
+        result = await self._send_command(payload)
+        self._validate_result("set_battery_icon", result)
+
+    async def set_temperature_unit(self, fahrenheit: bool) -> None:
+        """Set the default temperature unit shown on the screen (F or C)."""
+        payload = f"{COMMAND_SET_TEMPERATURE_UNIT}{'01' if fahrenheit else '00'}"
+        result = await self._send_command(payload)
+        self._validate_result("set_temperature_unit", result)
+
+    async def get_button_functions(self) -> dict[str, bool | None]:
+        """Read button functions, with None for reserved or unknown values."""
+        result = await self._send_command(COMMAND_GET_BUTTON_FUNCTIONS)
+        result = self._validate_result("get_button_functions", result, min_length=3)
+        # The protocol enables unit switching with 0x00 and source switching with 0x01.
+        return {
+            "unit_switch": result[1] == 0x00 if result[1] in (0x00, 0x01) else None,
+            "source_switch": result[2] == 0x01 if result[2] in (0x00, 0x01) else None,
+        }
+
+    async def set_button_functions(
+        self, unit_switch: bool | None = None, source_switch: bool | None = None
+    ) -> None:
+        """Allow or forbid the button actions; None keeps one as is."""
+        unit_byte = (
+            KEEP_BUTTON_FUNCTION
+            if unit_switch is None
+            else (0x00 if unit_switch else 0x01)
+        )
+        source_byte = (
+            KEEP_BUTTON_FUNCTION
+            if source_switch is None
+            else (0x01 if source_switch else 0x00)
+        )
+        payload = f"{COMMAND_SET_BUTTON_FUNCTIONS}{unit_byte:02x}{source_byte:02x}"
+        result = await self._send_command(payload)
+        self._validate_result("set_button_functions", result)
+
     def _validate_result(
         self, op_name: str, result: bytes | None, min_length: int | None = None
     ) -> bytes:

+ 480 - 0
tests/test_meter_pro_settings.py

@@ -0,0 +1,480 @@
+"""Display and calibration settings of the Meter Pro (and Meter Pro CO2)."""
+
+from unittest.mock import AsyncMock
+
+import pytest
+from bleak.backends.device import BLEDevice
+
+from switchbot import (
+    MeterProDateFormat,
+    MeterProDisplaySource,
+    MeterProDisplayZone,
+    MeterProZoneIcon,
+    SwitchbotOperationError,
+)
+from switchbot.devices.meter_pro import SwitchbotMeterPro, SwitchbotMeterProCO2
+
+
+def create_device(cls=SwitchbotMeterPro):
+    ble_device = BLEDevice(
+        address="aa:bb:cc:dd:ee:ff", name="any", details={"rssi": -80}
+    )
+    device = cls(ble_device)
+    device._send_command = AsyncMock(return_value=bytes.fromhex("01"))
+    return device
+
+
+# Captured from a Meter Pro (firmware 1.9): middle zone shows this device with
+# the indoor icon, bottom zone shows an Indoor/Outdoor Meter with the outdoor
+# icon, data update every 600 s, DD/MM, battery icon always shown.
+DISPLAY_SETTINGS = "011253000000000000d4e5f6a1b2c30258010101"
+
+
+@pytest.mark.asyncio
+async def test_get_display_settings():
+    device = create_device()
+    device._send_command.return_value = bytes.fromhex(DISPLAY_SETTINGS)
+
+    settings = await device.get_display_settings()
+
+    device._send_command.assert_called_with("570f690701")
+    assert settings == {
+        "middle": {
+            "icon": MeterProZoneIcon.INDOOR,
+            "source": MeterProDisplaySource.METER_PRO,
+            "source_mac": None,
+        },
+        "bottom": {
+            "icon": MeterProZoneIcon.OUTDOOR,
+            "source": MeterProDisplaySource.INDOOR_OUTDOOR_METER,
+            "source_mac": "D4:E5:F6:A1:B2:C3",
+        },
+        "data_update_interval": 600,
+        "date_format": MeterProDateFormat.DAY_MONTH,
+        "battery_icon_always": True,
+    }
+
+
+@pytest.mark.asyncio
+async def test_get_display_settings_factory_state():
+    """Factory layout: unused bottom zone, MM/DD, battery icon only when low."""
+    device = create_device()
+    device._send_command.return_value = bytes.fromhex(
+        "0110500000000000000000000000000258000100"
+    )
+
+    settings = await device.get_display_settings()
+
+    assert settings["bottom"] == {
+        "icon": None,
+        "source": MeterProDisplaySource.NONE,
+        "source_mac": None,
+    }
+    assert settings["date_format"] is MeterProDateFormat.MONTH_DAY
+    assert settings["battery_icon_always"] is False
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    ("date_code", "battery_code", "date_format", "battery_icon_always"),
+    [
+        (0x02, 0x00, None, False),
+        (0x00, 0xFE, MeterProDateFormat.MONTH_DAY, None),
+        (0xFF, 0xFF, None, None),
+    ],
+)
+async def test_get_display_settings_unknown_values(
+    date_code: int,
+    battery_code: int,
+    date_format: MeterProDateFormat | None,
+    battery_icon_always: bool | None,
+):
+    device = create_device()
+    response = bytearray.fromhex(DISPLAY_SETTINGS)
+    response[17] = date_code
+    response[19] = battery_code
+    device._send_command.return_value = bytes(response)
+
+    settings = await device.get_display_settings()
+
+    assert settings["date_format"] is date_format
+    assert settings["battery_icon_always"] is battery_icon_always
+    assert settings["data_update_interval"] == 600
+
+
+@pytest.mark.asyncio
+async def test_get_display_settings_short_response():
+    """Older firmware may stop after the MAC addresses."""
+    device = create_device()
+    device._send_command.return_value = bytes.fromhex(DISPLAY_SETTINGS[:30])
+
+    settings = await device.get_display_settings()
+
+    assert settings["bottom"]["source_mac"] == "D4:E5:F6:A1:B2:C3"
+    assert settings["data_update_interval"] is None
+    assert settings["date_format"] is None
+    assert settings["battery_icon_always"] is None
+
+
+@pytest.mark.asyncio
+async def test_get_display_settings_unknown_source_kept_raw():
+    device = create_device()
+    device._send_command.return_value = bytes.fromhex(
+        "011257000000000000aabbccddeeff0258010101"
+    )
+
+    settings = await device.get_display_settings()
+
+    assert settings["bottom"]["source"] == 7
+
+
+@pytest.mark.asyncio
+async def test_get_display_settings_weather_station_and_hub3():
+    device = create_device()
+    device._send_command.return_value = bytes.fromhex(
+        "011289aabbccddee01aabbccddee020258010101"
+    )
+
+    settings = await device.get_display_settings()
+
+    assert settings["middle"]["source"] is MeterProDisplaySource.WEATHER_STATION
+    assert settings["bottom"]["source"] is MeterProDisplaySource.HUB3
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    "response",
+    ["02", "011253000000"],  # error status, then response too short
+)
+async def test_get_display_settings_failure(response: str):
+    device = create_device()
+    device._send_command.return_value = bytes.fromhex(response)
+
+    with pytest.raises(SwitchbotOperationError):
+        await device.get_display_settings()
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    ("zone", "source", "mac", "icon", "expected_payload"),
+    [
+        (
+            MeterProDisplayZone.BOTTOM,
+            MeterProDisplaySource.INDOOR_OUTDOOR_METER,
+            "D4:E5:F6:A1:B2:C3",
+            MeterProZoneIcon.OUTDOOR,
+            "570f680701020203d4e5f6a1b2c3",
+        ),
+        (
+            MeterProDisplayZone.BOTTOM,
+            MeterProDisplaySource.NETWORK,
+            None,
+            MeterProZoneIcon.OUTDOOR,
+            "570f680701020206000000000000",
+        ),
+        (
+            MeterProDisplayZone.BOTTOM,
+            MeterProDisplaySource.NONE,
+            None,
+            None,
+            "570f68070102ff00000000000000",
+        ),
+        (
+            MeterProDisplayZone.MIDDLE,
+            MeterProDisplaySource.METER_PRO,
+            None,
+            MeterProZoneIcon.INDOOR,
+            "570f680701010105000000000000",
+        ),
+        (
+            MeterProDisplayZone.MIDDLE,
+            MeterProDisplaySource.METER_PLUS,
+            "aa-bb-cc-dd-ee-ff",
+            None,
+            "570f68070101ff02aabbccddeeff",
+        ),
+    ],
+)
+async def test_set_display_zone(
+    zone: MeterProDisplayZone,
+    source: MeterProDisplaySource,
+    mac: str | None,
+    icon: MeterProZoneIcon | None,
+    expected_payload: str,
+):
+    device = create_device()
+
+    await device.set_display_zone(zone, source, mac, icon)
+
+    device._send_command.assert_called_with(expected_payload)
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    ("source", "mac"),
+    [
+        (MeterProDisplaySource.METER, None),  # needs a MAC
+        (MeterProDisplaySource.NETWORK, "aa:bb:cc:dd:ee:ff"),  # takes none
+        (MeterProDisplaySource.NONE, "aa:bb:cc:dd:ee:ff"),  # takes none
+        (MeterProDisplaySource.METER, "aa:bb:cc"),  # malformed
+        (MeterProDisplaySource.METER, "zz:bb:cc:dd:ee:ff"),  # malformed
+    ],
+)
+async def test_set_display_zone_invalid(source: MeterProDisplaySource, mac: str):
+    device = create_device()
+
+    with pytest.raises(SwitchbotOperationError):
+        await device.set_display_zone(MeterProDisplayZone.BOTTOM, source, mac)
+    device._send_command.assert_not_called()
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    ("middle", "bottom", "expected_payload"),
+    [
+        (MeterProZoneIcon.INDOOR, MeterProZoneIcon.OUTDOOR, "570f680701030102"),
+        (None, MeterProZoneIcon.INDOOR, "570f680701030f01"),
+        (MeterProZoneIcon.OUTDOOR, None, "570f68070103020f"),
+    ],
+)
+async def test_set_zone_icons(
+    middle: MeterProZoneIcon | None,
+    bottom: MeterProZoneIcon | None,
+    expected_payload: str,
+):
+    device = create_device()
+
+    await device.set_zone_icons(middle, bottom)
+
+    device._send_command.assert_called_with(expected_payload)
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    ("seconds", "expected_payload"),
+    [(300, "570f68070105012c"), (600, "570f680701050258"), (1800, "570f680701050708")],
+)
+async def test_set_data_update_interval(seconds: int, expected_payload: str):
+    device = create_device()
+
+    await device.set_data_update_interval(seconds)
+
+    device._send_command.assert_called_with(expected_payload)
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize("seconds", [0, -1, 0x10000, True, 300.0, "300"])
+async def test_set_data_update_interval_invalid(seconds: object):
+    device = create_device()
+
+    with pytest.raises(SwitchbotOperationError):
+        await device.set_data_update_interval(seconds)
+    device._send_command.assert_not_called()
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    ("date_format", "expected_payload"),
+    [
+        (MeterProDateFormat.MONTH_DAY, "570f6807010700"),
+        (MeterProDateFormat.DAY_MONTH, "570f6807010701"),
+    ],
+)
+async def test_set_date_format(date_format: MeterProDateFormat, expected_payload: str):
+    device = create_device()
+
+    await device.set_date_format(date_format)
+
+    device._send_command.assert_called_with(expected_payload)
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    ("always", "expected_payload"),
+    [(True, "570f6807010801"), (False, "570f6807010800")],
+)
+async def test_set_battery_icon(always: bool, expected_payload: str):
+    device = create_device()
+
+    await device.set_battery_icon(always)
+
+    device._send_command.assert_called_with(expected_payload)
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    ("fahrenheit", "expected_payload"),
+    [(True, "570f6807010901"), (False, "570f6807010900")],
+)
+async def test_set_temperature_unit(fahrenheit: bool, expected_payload: str):
+    device = create_device()
+
+    await device.set_temperature_unit(fahrenheit)
+
+    device._send_command.assert_called_with(expected_payload)
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    ("response", "expected"),
+    [
+        ("010101", {"unit_switch": False, "source_switch": True}),
+        ("010000", {"unit_switch": True, "source_switch": False}),
+        ("01ff01", {"unit_switch": None, "source_switch": True}),
+        ("0100ff", {"unit_switch": True, "source_switch": None}),
+        ("01ffff", {"unit_switch": None, "source_switch": None}),
+        ("010202", {"unit_switch": None, "source_switch": None}),
+    ],
+)
+async def test_get_button_functions(response: str, expected: dict[str, bool | None]):
+    device = create_device()
+    device._send_command.return_value = bytes.fromhex(response)
+
+    assert await device.get_button_functions() == expected
+    device._send_command.assert_called_with("570f690704")
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    ("unit_switch", "source_switch", "expected_payload"),
+    [
+        (True, False, "570f680701060000"),
+        (False, True, "570f680701060101"),
+        (None, True, "570f68070106ff01"),
+        (False, None, "570f6807010601ff"),
+    ],
+)
+async def test_set_button_functions(
+    unit_switch: bool | None, source_switch: bool | None, expected_payload: str
+):
+    device = create_device()
+
+    await device.set_button_functions(unit_switch, source_switch)
+
+    device._send_command.assert_called_with(expected_payload)
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    ("response", "temperature", "humidity"),
+    [
+        ("01000000", 0.0, 0),  # factory state: sign bits cleared
+        ("01808000", 0.0, 0),
+        ("01018305", -1.5, 3),
+        ("01820a03", 2.3, -10),
+        ("01800005", 0.5, 0),
+    ],
+)
+async def test_get_calibration(response: str, temperature: float, humidity: int):
+    device = create_device()
+    device._send_command.return_value = bytes.fromhex(response)
+
+    calibration = await device.get_calibration()
+
+    device._send_command.assert_called_with("570f6903")
+    assert calibration == {"temperature": temperature, "humidity": humidity}
+    assert str(calibration["temperature"]) != "-0.0"
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize("response", ["0180800a", "0180e400", "01806400"])
+async def test_get_calibration_rejects_invalid_values(response: str):
+    device = create_device()
+    device._send_command.return_value = bytes.fromhex(response)
+
+    with pytest.raises(SwitchbotOperationError, match="Invalid calibration response"):
+        await device.get_calibration()
+
+
+@pytest.mark.asyncio
+async def test_get_calibration_short_response():
+    device = create_device()
+    device._send_command.return_value = bytes.fromhex("0101")
+
+    with pytest.raises(SwitchbotOperationError):
+        await device.get_calibration()
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    ("temperature", "humidity", "expected_payload"),
+    [
+        (0, 0, "570f6803808000"),
+        (-1.5, 3, "570f6803018305"),
+        (2.3, -10, "570f6803820a03"),
+        (0.5, 0, "570f6803808005"),  # positive below one degree keeps its sign
+        (-0.5, 0, "570f6803008005"),
+        (1.25, 0, "570f6803818003"),  # rounded to one decimal
+    ],
+)
+async def test_set_calibration(
+    temperature: float, humidity: int, expected_payload: str
+):
+    device = create_device()
+
+    await device.set_calibration(temperature, humidity)
+
+    device._send_command.assert_called_with(expected_payload)
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    ("temperature", "humidity"),
+    [(128, 0), (-128, 0), (0, 100), (0, -100), (0, True), (0, 0.5), (0, "1")],
+)
+async def test_set_calibration_invalid(temperature: float, humidity: object):
+    device = create_device()
+
+    with pytest.raises(SwitchbotOperationError):
+        await device.set_calibration(temperature, humidity)
+    device._send_command.assert_not_called()
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    ("method", "args"),
+    [
+        ("set_calibration", (1.0, 1)),
+        ("set_display_zone", (MeterProDisplayZone.BOTTOM, MeterProDisplaySource.NONE)),
+        ("set_zone_icons", (MeterProZoneIcon.INDOOR,)),
+        ("set_data_update_interval", (600,)),
+        ("set_date_format", (MeterProDateFormat.DAY_MONTH,)),
+        ("set_battery_icon", (True,)),
+        ("set_temperature_unit", (False,)),
+        ("set_button_functions", (True, True)),
+    ],
+)
+async def test_setters_raise_on_device_error(method: str, args: tuple):
+    device = create_device()
+    device._send_command.return_value = bytes.fromhex("05")  # not supported
+
+    with pytest.raises(SwitchbotOperationError):
+        await getattr(device, method)(*args)
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    ("method", "args", "expected_payload"),
+    [
+        ("set_calibration", (1.0, 1), "570f6803818100"),
+        (
+            "set_display_zone",
+            (MeterProDisplayZone.BOTTOM, MeterProDisplaySource.NETWORK),
+            "570f68070102ff06000000000000",
+        ),
+        ("set_zone_icons", (MeterProZoneIcon.INDOOR,), "570f68070103010f"),
+        ("set_data_update_interval", (600,), "570f680701050258"),
+        ("set_date_format", (MeterProDateFormat.DAY_MONTH,), "570f6807010701"),
+        ("set_battery_icon", (True,), "570f6807010801"),
+        ("set_temperature_unit", (False,), "570f6807010900"),
+        ("set_button_functions", (True, True), "570f680701060001"),
+    ],
+)
+async def test_co2_variant_shares_display_settings(
+    method: str, args: tuple, expected_payload: str
+):
+    device = create_device(SwitchbotMeterProCO2)
+
+    await getattr(device, method)(*args)
+
+    device._send_command.assert_called_with(expected_payload)