Skip to content
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

Switch authentication from phone to email #10

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Copy all files in the `custom_components`/`yeelock` folder to your Home Assistan
## Configuration
1. Setup your Yeelock first in the Yeelock app. You will need the QR code that came in the box to do this.
3. Once the integration is installed & you have restarted Home Assistant, your Yeelock will be detected & shown automatically on the `Devices and services` page.
4. You will need to input your phone's country code, phone number (without leading zero) and Yeelock account password.
4. You will need to input your email (login) and Yeelock account password.
5. To use the automatic re-lock, tap the button underneath the lock / unlock toggle.

## Known issues
Expand Down
23 changes: 9 additions & 14 deletions custom_components/yeelock/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from bluetooth_data_tools import human_readable_name
from homeassistant import config_entries
from homeassistant.const import (
CONF_COUNTRY_CODE,
CONF_EMAIL,
CONF_PASSWORD,
CONF_NAME,
CONF_MAC,
Expand All @@ -24,14 +24,13 @@
from homeassistant.components.bluetooth import BluetoothServiceInfoBleak
from homeassistant.data_entry_flow import FlowResult

from .const import CONF_PHONE, DOMAIN
from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)

STEP_USER_DATA_SCHEMA = voluptuous.Schema(
{
voluptuous.Required(CONF_COUNTRY_CODE): str,
voluptuous.Required(CONF_PHONE): str,
voluptuous.Required(CONF_EMAIL): str,
voluptuous.Required(CONF_PASSWORD): str,
voluptuous.Required(CONF_NAME): str,
voluptuous.Required(CONF_MAC): str,
Expand Down Expand Up @@ -72,8 +71,7 @@ async def async_step_bluetooth(

self._schema = voluptuous.Schema(
{
voluptuous.Required(CONF_COUNTRY_CODE): str,
voluptuous.Required(CONF_PHONE): str,
voluptuous.Required(CONF_EMAIL): str,
voluptuous.Required(CONF_PASSWORD): str,
}
)
Expand Down Expand Up @@ -103,28 +101,25 @@ async def async_step_cloud(
_LOGGER.debug("Get token")
login = await self._api_wrapper(
method="post",
url="https://api.yeeloc.com/oauth/access_token",
url="https://api.yeeloc.com/v2/auth/by/password",
params={
"grant_type": "password",
"client_id": "yeeloc",
"client_secret": "adb03414981961952ccf40a1b4031d12",
"username": user_input[CONF_PHONE],
"account": user_input[CONF_EMAIL],
"password": user_input[CONF_PASSWORD],
"zone": user_input[CONF_COUNTRY_CODE],
},
headers={
"content-type": "application/x-www-form-urlencoded; charset=UTF-8"
},
)

try:
if login["access_token"]:
if login.get("data").get("access_token"):
access_token = login.get("data").get("access_token")
# Get locks
_LOGGER.debug("Get locks")
locks = await self._api_wrapper(
method="get",
url="https://api.yeeloc.com/lock",
headers={"Authorization": "Bearer " + login["access_token"]},
headers={"Authorization": "Bearer " + access_token},
)

_LOGGER.debug(locks)
Expand Down
2 changes: 0 additions & 2 deletions custom_components/yeelock/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
Platform.LOCK,
]

CONF_PHONE = "phone"

UUID_BATTERY_LEVEL = "00002a19-0000-1000-8000-00805f9b34fb"
UUID_COMMAND = "58af3dca-6fc0-4fa3-9464-74662f043a3b"
UUID_NOTIFY = "58af3dca-6fc0-4fa3-9464-74662f043a3a"
Expand Down
3 changes: 1 addition & 2 deletions custom_components/yeelock/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"title": "Yeelock",
"description": "Devices must be set-up in the Yeelock app first (requires an account).",
"data": {
"country_code": "Country Code",
"phone": "Phone Number",
"email": "E-Mail",
"password": "[%key:common::config_flow::data::password%]",
"name": "[%key:common::config_flow::data::name%]",
"mac": "MAC Address",
Expand Down
3 changes: 1 addition & 2 deletions custom_components/yeelock/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"title": "Yeelock",
"description": "Devices must be set-up in the Yeelock app first (requires an account).",
"data": {
"country_code": "Country Code",
"phone": "Phone Number",
"email": "E-Mail (login)",
"password": "Password",
"name": "Name",
"mac": "MAC Address",
Expand Down