Skip to content

Commit

Permalink
Supress warning from unknown and unsupported capabilities (#137)
Browse files Browse the repository at this point in the history
* Supress warning from unknown capability 0x0040

* Reduce log level of unsupported capabilities
  • Loading branch information
mill1000 authored Jul 10, 2024
1 parent ca14268 commit ab34eb4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
9 changes: 8 additions & 1 deletion msmart/device/AC/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CapabilityId(IntEnum):
WIND_ON_ME = 0x0032
WIND_OFF_ME = 0x0033
SELF_CLEAN = 0x0039 # AKA Active Clean
_UNKNOWN = 0x0040 # Unknown ID from various logs
ONE_KEY_NO_WIND_ON_ME = 0x0042
BREEZE_CONTROL = 0x0043 # AKA "FA No Wind Sense"
RATE_SELECT = 0x0048
Expand Down Expand Up @@ -511,6 +512,7 @@ def get_value(w) -> Callable[[int], bool]: return lambda v: v == w
# CapabilityId.TEMPERATURES too complex to be handled here
CapabilityId.WIND_OFF_ME: reader("wind_off_me", get_value(1)),
CapabilityId.WIND_ON_ME: reader("wind_on_me", get_value(1)),
# CapabilityId._UNKNOWN is a special case
}

count = payload[1]
Expand Down Expand Up @@ -574,8 +576,13 @@ def apply(d, v): return {d.name: d.read(v)}
self._capabilities["decimals"] = (
caps[9] if size > 6 else caps[2]) != 0

elif capability_id == CapabilityId._UNKNOWN:
# Supress warnings from unknown capability
_LOGGER.debug(
"Ignored unknown capability. ID: 0x%04X, Size: %d.", capability_id, size)

else:
_LOGGER.warning(
_LOGGER.info(
"Unsupported capability. ID: 0x%04X, Size: %d.", capability_id, size)

# Advanced to next capability
Expand Down
16 changes: 9 additions & 7 deletions msmart/device/AC/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,13 @@ def test_capabilities_2(self) -> None:
"aa3dac00000000000203b50a12020101180001001402010115020101160201001a020101100201011f020100250207203c203c203c00400001000100c83a")

# Test case includes an unknown capability 0x40 that generates a warning
with self.assertLogs("msmart") as log:
with self.assertLogs("msmart", logging.DEBUG) as log:
resp = self._test_build_response(TEST_CAPABILITIES_RESPONSE)
resp = cast(CapabilitiesResponse, resp)

# Check warning is generated for ID 0x0040
self.assertRegex(log.output[0], "Unknown capability. ID: 0x0040")
# Check debug message is generated for ID 0x0040
self.assertRegex("\n".join(log.output),
"Ignored unknown capability. ID: 0x0040")

EXPECTED_RAW_CAPABILITIES = {
"eco_mode": True, "eco_mode_2": False, "silky_cool": False,
Expand Down Expand Up @@ -473,13 +474,14 @@ def test_additional_capabilities(self) -> None:
TEST_CAPABILITIES_RESPONSE = bytes.fromhex(
"aa3dac00000000000303b50a12020101430001011402010115020101160201001a020101100201011f020103250207203c203c203c05400001000100c805")

# Test case includes an unknown capability 0x40 that generates a warning
with self.assertLogs("msmart") as log:
# Test case includes an unknown capability 0x40 that generates a log
with self.assertLogs("msmart", logging.DEBUG) as log:
resp = self._test_build_response(TEST_CAPABILITIES_RESPONSE)
resp = cast(CapabilitiesResponse, resp)

# Check warning is generated for ID 0x0040
self.assertRegex(log.output[0], "Unknown capability. ID: 0x0040")
# Check debug message is generated for ID 0x0040
self.assertRegex("\n".join(log.output),
"Ignored unknown capability. ID: 0x0040")

EXPECTED_RAW_CAPABILITIES = {
"eco_mode": True, "eco_mode_2": False,
Expand Down

0 comments on commit ab34eb4

Please sign in to comment.