-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Add support for SwitchBot Lock #84673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a4406c7
Added support for SwitchBot Lock
dsypniewski 5bb0587
Updated PySwitchbot to 0.32.1
dsypniewski 76896bc
Updated .coveragerc
dsypniewski b702943
Removed unnecessary condition
dsypniewski c988977
Using library method to verify encryption key
dsypniewski d08b628
Added config flow tests
dsypniewski 72d3d9e
Remove link from config flow description
dsypniewski 8a13b59
Added one more test for config flow
dsypniewski c9fbe99
Updated CODEOWNERS
dsypniewski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| """Support for SwitchBot lock platform.""" | ||
| from typing import Any | ||
|
|
||
| import switchbot | ||
| from switchbot.const import LockStatus | ||
|
|
||
| from homeassistant.components.lock import LockEntity | ||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
|
||
| from .const import DOMAIN | ||
| from .coordinator import SwitchbotDataUpdateCoordinator | ||
| from .entity import SwitchbotEntity | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback | ||
| ) -> None: | ||
| """Set up Switchbot lock based on a config entry.""" | ||
| coordinator: SwitchbotDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] | ||
| async_add_entities([(SwitchBotLock(coordinator))]) | ||
|
|
||
|
|
||
| # noinspection PyAbstractClass | ||
| class SwitchBotLock(SwitchbotEntity, LockEntity): | ||
| """Representation of a Switchbot lock.""" | ||
|
|
||
| _device: switchbot.SwitchbotLock | ||
|
|
||
| def __init__(self, coordinator: SwitchbotDataUpdateCoordinator) -> None: | ||
| """Initialize the entity.""" | ||
| super().__init__(coordinator) | ||
| self._async_update_attrs() | ||
|
|
||
| def _async_update_attrs(self) -> None: | ||
| """Update the entity attributes.""" | ||
| status = self._device.get_lock_status() | ||
| self._attr_is_locked = status is LockStatus.LOCKED | ||
| self._attr_is_locking = status is LockStatus.LOCKING | ||
| self._attr_is_unlocking = status is LockStatus.UNLOCKING | ||
| self._attr_is_jammed = status in { | ||
| LockStatus.LOCKING_STOP, | ||
| LockStatus.UNLOCKING_STOP, | ||
| } | ||
|
|
||
| async def async_lock(self, **kwargs: Any) -> None: | ||
| """Lock the lock.""" | ||
| self._last_run_success = await self._device.lock() | ||
| self.async_write_ha_state() | ||
|
|
||
| async def async_unlock(self, **kwargs: Any) -> None: | ||
| """Unlock the lock.""" | ||
| self._last_run_success = await self._device.unlock() | ||
| self.async_write_ha_state() |
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
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
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
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.