Update PySwitchbot to 0.8.0 and add password configuration option (#33252)

* Update PySwitchbot to 0.8.0 and added password configuration

* Removed unchanged retry_count attribute

* Fix dependencies and formatting

* Removed default value for password and use config.get instead
This commit is contained in:
Jaryl Chng 2020-03-27 03:55:00 +08:00 committed by GitHub
parent 3dc6612cd9
commit 6c6318d18f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View File

@ -2,7 +2,7 @@
"domain": "switchbot",
"name": "SwitchBot",
"documentation": "https://www.home-assistant.io/integrations/switchbot",
"requirements": ["PySwitchbot==0.6.2"],
"requirements": ["PySwitchbot==0.8.0"],
"dependencies": [],
"codeowners": ["@danielhiversen"]
}

View File

@ -7,7 +7,7 @@ import switchbot
import voluptuous as vol
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice
from homeassistant.const import CONF_MAC, CONF_NAME
from homeassistant.const import CONF_MAC, CONF_NAME, CONF_PASSWORD
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.restore_state import RestoreEntity
@ -19,6 +19,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_MAC): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_PASSWORD): cv.string,
}
)
@ -27,20 +28,21 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Perform the setup for Switchbot devices."""
name = config.get(CONF_NAME)
mac_addr = config[CONF_MAC]
add_entities([SwitchBot(mac_addr, name)])
password = config.get(CONF_PASSWORD)
add_entities([SwitchBot(mac_addr, name, password)])
class SwitchBot(SwitchDevice, RestoreEntity):
"""Representation of a Switchbot."""
def __init__(self, mac, name) -> None:
def __init__(self, mac, name, password) -> None:
"""Initialize the Switchbot."""
self._state = None
self._last_run_success = None
self._name = name
self._mac = mac
self._device = switchbot.Switchbot(mac=mac)
self._device = switchbot.Switchbot(mac=mac, password=password)
async def async_added_to_hass(self):
"""Run when entity about to be added."""

View File

@ -72,7 +72,7 @@ PyRMVtransport==0.2.9
PySocks==1.7.1
# homeassistant.components.switchbot
# PySwitchbot==0.6.2
# PySwitchbot==0.8.0
# homeassistant.components.transport_nsw
PyTransportNSW==0.1.1