mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 11:13:34 +00:00
Add update-credentials command (#620)
* Add change credentials command * Rename command and add prompts for credential update
This commit is contained in:
parent
554fe0a96e
commit
2d8a8d9511
23
kasa/cli.py
23
kasa/cli.py
@ -997,5 +997,28 @@ async def turn_on_behavior(dev: SmartBulb, type, last, preset):
|
||||
return await dev.set_turn_on_behavior(settings)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@pass_dev
|
||||
@click.option(
|
||||
"--username", required=True, prompt=True, help="New username to set on the device"
|
||||
)
|
||||
@click.option(
|
||||
"--password", required=True, prompt=True, help="New password to set on the device"
|
||||
)
|
||||
async def update_credentials(dev, username, password):
|
||||
"""Update device credentials for authenticated devices."""
|
||||
# Importing here as this is not really a public interface for now
|
||||
from kasa.tapo import TapoDevice
|
||||
|
||||
if not isinstance(dev, TapoDevice):
|
||||
raise NotImplementedError(
|
||||
"Credentials can only be updated on authenticated devices."
|
||||
)
|
||||
|
||||
click.confirm("Do you really want to replace the existing credentials?", abort=True)
|
||||
|
||||
return await dev.update_credentials(username, password)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli()
|
||||
|
@ -321,3 +321,18 @@ class TapoDevice(SmartDevice):
|
||||
raise
|
||||
|
||||
_LOGGER.debug("Received an expected for wifi join, but this is expected")
|
||||
|
||||
async def update_credentials(self, username: str, password: str):
|
||||
"""Update device credentials.
|
||||
|
||||
This will replace the existing authentication credentials on the device.
|
||||
"""
|
||||
t = self.internal_state["time"]
|
||||
payload = {
|
||||
"account": {
|
||||
"username": base64.b64encode(username.encode()).decode(),
|
||||
"password": base64.b64encode(password.encode()).decode(),
|
||||
},
|
||||
"time": t,
|
||||
}
|
||||
return await self.protocol.query({"set_qs_info": payload})
|
||||
|
Loading…
Reference in New Issue
Block a user