FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Ensure bulb state is restored when turning back on by bdraco · Pull Request #330 · python-kasa/python-kasa · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 11 additions & 2 deletions kasa/smartbulb.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class HSV(NamedTuple):
r"KL430": ColorTempRange(2500, 9000),
}


NON_COLOR_MODE_FLAGS = {"transition_period", "on_off"}

_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -211,8 +214,14 @@ async def set_light_state(self, state: Dict, *, transition: int = None) -> Dict:
if "on_off" not in state:
state["on_off"] = 1

# This is necessary to allow turning on into a specific state
state["ignore_default"] = 1
# If we are turning on without any color mode flags,
# we do not want to set ignore_default to ensure
# we restore the previous state.
if state["on_off"] and NON_COLOR_MODE_FLAGS.issuperset(state):
state["ignore_default"] = 0
else:
# This is necessary to allow turning on into a specific state
state["ignore_default"] = 1

light_state = await self._query_helper(
self.LIGHT_SERVICE, self.SET_LIGHT_METHOD, state
Expand Down
13 changes: 13 additions & 0 deletions kasa/tests/test_bulb.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,16 @@ async def test_non_dimmable(dev):
assert dev.brightness == 0
with pytest.raises(SmartDeviceException):
await dev.set_brightness(100)


@bulb
async def test_ignore_default_not_set_without_color_mode_change_turn_on(dev, mocker):
query_helper = mocker.patch("kasa.SmartBulb._query_helper")
# When turning back without settings, ignore default to restore the state
await dev.turn_on()
args, kwargs = query_helper.call_args_list[0]
assert args[2] == {"on_off": 1, "ignore_default": 0}

await dev.turn_off()
args, kwargs = query_helper.call_args_list[1]
assert args[2] == {"on_off": 0, "ignore_default": 1}

Back | FazBrowse Home | New Git URL