mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Switchmate (#16395)
* Switchmate * switchmate * swithcmate * switchmate * switchmate * switchmate * Make switchmate a bit more robust * style * style * style * Use external lib for switchmate * add_entities * Update requirements_all.txt * unnecessary string format
This commit is contained in:
parent
3824582e68
commit
cb542a90eb
@ -12,16 +12,12 @@ import voluptuous as vol
|
|||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components.switch import SwitchDevice, PLATFORM_SCHEMA
|
from homeassistant.components.switch import SwitchDevice, PLATFORM_SCHEMA
|
||||||
from homeassistant.const import CONF_NAME, CONF_MAC
|
from homeassistant.const import CONF_NAME, CONF_MAC
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
|
||||||
|
|
||||||
REQUIREMENTS = ['bluepy==1.1.4']
|
REQUIREMENTS = ['pySwitchmate==0.3']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEFAULT_NAME = 'Switchmate'
|
DEFAULT_NAME = 'Switchmate'
|
||||||
HANDLE = 0x2e
|
|
||||||
ON_KEY = b'\x00'
|
|
||||||
OFF_KEY = b'\x01'
|
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(minutes=30)
|
SCAN_INTERVAL = timedelta(minutes=30)
|
||||||
|
|
||||||
@ -34,7 +30,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
def setup_platform(hass, config, add_entities, discovery_info=None) -> None:
|
def setup_platform(hass, config, add_entities, discovery_info=None) -> None:
|
||||||
"""Perform the setup for Switchmate devices."""
|
"""Perform the setup for Switchmate devices."""
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
mac_addr = config.get(CONF_MAC)
|
mac_addr = config[CONF_MAC]
|
||||||
add_entities([Switchmate(mac_addr, name)], True)
|
add_entities([Switchmate(mac_addr, name)], True)
|
||||||
|
|
||||||
|
|
||||||
@ -43,17 +39,10 @@ class Switchmate(SwitchDevice):
|
|||||||
|
|
||||||
def __init__(self, mac, name) -> None:
|
def __init__(self, mac, name) -> None:
|
||||||
"""Initialize the Switchmate."""
|
"""Initialize the Switchmate."""
|
||||||
# pylint: disable=import-error
|
import switchmate
|
||||||
import bluepy
|
|
||||||
self._state = False
|
|
||||||
self._name = name
|
self._name = name
|
||||||
self._mac = mac
|
self._mac = mac
|
||||||
try:
|
self._device = switchmate.Switchmate(mac=mac)
|
||||||
self._device = bluepy.btle.Peripheral(self._mac,
|
|
||||||
bluepy.btle.ADDR_TYPE_RANDOM)
|
|
||||||
except bluepy.btle.BTLEException:
|
|
||||||
_LOGGER.error("Failed to set up switchmate")
|
|
||||||
raise PlatformNotReady()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
@ -67,17 +56,17 @@ class Switchmate(SwitchDevice):
|
|||||||
|
|
||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
"""Synchronize state with switch."""
|
"""Synchronize state with switch."""
|
||||||
self._state = self._device.readCharacteristic(HANDLE) == ON_KEY
|
self._device.update()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return true if it is on."""
|
"""Return true if it is on."""
|
||||||
return self._state
|
return self._device.state
|
||||||
|
|
||||||
def turn_on(self, **kwargs) -> None:
|
def turn_on(self, **kwargs) -> None:
|
||||||
"""Turn the switch on."""
|
"""Turn the switch on."""
|
||||||
self._device.writeCharacteristic(HANDLE, ON_KEY, True)
|
self._device.turn_on()
|
||||||
|
|
||||||
def turn_off(self, **kwargs) -> None:
|
def turn_off(self, **kwargs) -> None:
|
||||||
"""Turn the switch off."""
|
"""Turn the switch off."""
|
||||||
self._device.writeCharacteristic(HANDLE, OFF_KEY, True)
|
self._device.turn_off()
|
||||||
|
@ -190,7 +190,6 @@ blinkstick==1.1.8
|
|||||||
blockchain==1.4.4
|
blockchain==1.4.4
|
||||||
|
|
||||||
# homeassistant.components.light.decora
|
# homeassistant.components.light.decora
|
||||||
# homeassistant.components.switch.switchmate
|
|
||||||
# bluepy==1.1.4
|
# bluepy==1.1.4
|
||||||
|
|
||||||
# homeassistant.components.sensor.bme680
|
# homeassistant.components.sensor.bme680
|
||||||
@ -749,6 +748,9 @@ pyHS100==0.3.3
|
|||||||
# homeassistant.components.rfxtrx
|
# homeassistant.components.rfxtrx
|
||||||
pyRFXtrx==0.23
|
pyRFXtrx==0.23
|
||||||
|
|
||||||
|
# homeassistant.components.switch.switchmate
|
||||||
|
pySwitchmate==0.3
|
||||||
|
|
||||||
# homeassistant.components.sensor.tibber
|
# homeassistant.components.sensor.tibber
|
||||||
pyTibber==0.4.1
|
pyTibber==0.4.1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user