Skip to content

Commit 42d4f40

Browse files
authored
Use snake_case style for fan modes (#321)
1 parent 7826d11 commit 42d4f40

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

switchbot/adv_parsers/fan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def process_fan(data: bytes | None, mfr_data: bytes | None) -> dict[str, bool |
1515
_seq_num = device_data[0]
1616
_isOn = bool(device_data[1] & 0b10000000)
1717
_mode = (device_data[1] & 0b01110000) >> 4
18-
_mode = FanMode(_mode).name if 1 <= _mode <= 4 else None
18+
_mode = FanMode(_mode).name.lower() if 1 <= _mode <= 4 else None
1919
_nightLight = (device_data[1] & 0b00001100) >> 2
2020
_oscillate_left_and_right = bool(device_data[1] & 0b00000010)
2121
_oscillate_up_and_down = bool(device_data[1] & 0b00000001)

switchbot/const/fan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class FanMode(Enum):
1111

1212
@classmethod
1313
def get_modes(cls) -> list[str]:
14-
return [mode.name for mode in cls]
14+
return [mode.name.lower() for mode in cls]

switchbot/devices/fan.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
COMMAND_START_OSCILLATION = f"{COMMAND_HEAD}020101ff"
2222
COMMAND_STOP_OSCILLATION = f"{COMMAND_HEAD}020102ff"
2323
COMMAND_SET_MODE = {
24-
FanMode.NORMAL.name: f"{COMMAND_HEAD}030101ff",
25-
FanMode.NATURAL.name: f"{COMMAND_HEAD}030102ff",
26-
FanMode.SLEEP.name: f"{COMMAND_HEAD}030103",
27-
FanMode.BABY.name: f"{COMMAND_HEAD}030104",
24+
FanMode.NORMAL.name.lower(): f"{COMMAND_HEAD}030101ff",
25+
FanMode.NATURAL.name.lower(): f"{COMMAND_HEAD}030102ff",
26+
FanMode.SLEEP.name.lower(): f"{COMMAND_HEAD}030103",
27+
FanMode.BABY.name.lower(): f"{COMMAND_HEAD}030104",
2828
}
2929
COMMAND_SET_PERCENTAGE = f"{COMMAND_HEAD}0302" # +speed
3030
COMMAND_GET_BASIC_INFO = "570f428102"
@@ -48,7 +48,7 @@ async def get_basic_info(self) -> dict[str, Any] | None:
4848
isOn = bool(_data[3] & 0b10000000)
4949
oscillating = bool(_data[3] & 0b01100000)
5050
_mode = _data[8] & 0b00000111
51-
mode = FanMode(_mode).name if 1 <= _mode <= 4 else None
51+
mode = FanMode(_mode).name.lower() if 1 <= _mode <= 4 else None
5252
speed = _data[9]
5353
firmware = _data1[2] / 10.0
5454

tests/test_adv_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,7 +2123,7 @@ def test_circulator_fan_active() -> None:
21232123
"data": {
21242124
"sequence_number": 126,
21252125
"isOn": False,
2126-
"mode": "BABY",
2126+
"mode": "baby",
21272127
"nightLight": 3,
21282128
"oscillating": False,
21292129
"battery": 82,
@@ -2157,7 +2157,7 @@ def test_circulator_fan_passive() -> None:
21572157
"data": {
21582158
"sequence_number": 126,
21592159
"isOn": False,
2160-
"mode": "BABY",
2160+
"mode": "baby",
21612161
"nightLight": 3,
21622162
"oscillating": False,
21632163
"battery": 82,

tests/test_fan.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ async def mock_get_basic_info(arg):
8989
(
9090
bytearray(b"\x01\x02W\x82g\xf5\xde4\x01=dPP\x03\x14P\x00\x00\x00\x00"),
9191
bytearray(b"\x01W\x0b\x17\x01"),
92-
[87, True, False, "NORMAL", 61, 1.1],
92+
[87, True, False, "normal", 61, 1.1],
9393
),
9494
(
9595
bytearray(b"\x01\x02U\xc2g\xf5\xde4\x04+dPP\x03\x14P\x00\x00\x00\x00"),
9696
bytearray(b"\x01U\x0b\x17\x01"),
97-
[85, True, True, "BABY", 43, 1.1],
97+
[85, True, True, "baby", 43, 1.1],
9898
),
9999
],
100100
)
@@ -120,9 +120,9 @@ async def mock_get_basic_info(arg):
120120

121121
@pytest.mark.asyncio
122122
async def test_set_preset_mode():
123-
fan_device = create_device_for_command_testing({"mode": "BABY"})
124-
await fan_device.set_preset_mode("BABY")
125-
assert fan_device.get_current_mode() == "BABY"
123+
fan_device = create_device_for_command_testing({"mode": "baby"})
124+
await fan_device.set_preset_mode("baby")
125+
assert fan_device.get_current_mode() == "baby"
126126

127127

128128
@pytest.mark.asyncio
@@ -169,4 +169,4 @@ async def test_turn_off():
169169

170170

171171
def test_get_modes():
172-
assert FanMode.get_modes() == ["NORMAL", "NATURAL", "SLEEP", "BABY"]
172+
assert FanMode.get_modes() == ["normal", "natural", "sleep", "baby"]

0 commit comments

Comments
 (0)