mirror of
https://github.com/esphome/esphome.git
synced 2025-03-14 14:48:18 +00:00
Add Sonoff RF Bridge Support
This commit is contained in:
parent
21c22fe04a
commit
419af46ccb
18
esphomeyaml/components/binary_sensor/sonoff_rf_bridge.py
Normal file
18
esphomeyaml/components/binary_sensor/sonoff_rf_bridge.py
Normal file
@ -0,0 +1,18 @@
|
||||
from esphomeyaml.components import binary_sensor, sonoff_rf_bridge
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_NAME
|
||||
from esphomeyaml.helpers import get_variable
|
||||
|
||||
DEPENDENCIES = ['sonoff_rf_bridge']
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(sonoff_rf_bridge.CONF_SONOFF_RF_BRIDGE_ID):
|
||||
cv.use_variable_id(sonoff_rf_bridge.SonoffRFBridge)
|
||||
}).extend(sonoff_rf_bridge.FRAME_SCHEMA.schema))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for hub in get_variable(config[sonoff_rf_bridge.CONF_SONOFF_RF_BRIDGE_ID]):
|
||||
yield
|
||||
rhs = hub.Pmake_binary_sensor(config[CONF_NAME], *sonoff_rf_bridge.get_args(config))
|
||||
binary_sensor.register_binary_sensor(rhs, config)
|
52
esphomeyaml/components/sonoff_rf_bridge.py
Normal file
52
esphomeyaml/components/sonoff_rf_bridge.py
Normal file
@ -0,0 +1,52 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import config_validation as cv
|
||||
from esphomeyaml.components.uart import UARTComponent
|
||||
from esphomeyaml.const import CONF_DATA, CONF_HIGH, CONF_ID, CONF_LOW, CONF_SYNC, CONF_UART_ID
|
||||
from esphomeyaml.helpers import App, Pvariable, esphomelib_ns, get_variable
|
||||
|
||||
CONF_SONOFF_RF_BRIDGE_ID = 'sonoff_rf_bridge_id'
|
||||
SonoffRFBridge = esphomelib_ns.SonoffRFBridge
|
||||
SonoffRFBinarySensor = esphomelib_ns.SonoffRFBinarySensor
|
||||
SonoffRFSwitch = esphomelib_ns.SonoffRFSwitch
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(SonoffRFBridge),
|
||||
cv.GenerateID(CONF_UART_ID): cv.use_variable_id(UARTComponent),
|
||||
})
|
||||
|
||||
|
||||
def validate_data(value):
|
||||
value = cv.string_strict(value)
|
||||
if len(value) != 32:
|
||||
raise vol.Invalid("Data must be 32 characters long!")
|
||||
for x in value:
|
||||
if x not in ('0', '1'):
|
||||
raise vol.Invalid(u"Each character in data must either be 0 or 1, not {}".format(x))
|
||||
return value
|
||||
|
||||
|
||||
FRAME_SCHEMA = vol.Schema({
|
||||
vol.Required(CONF_SYNC): cv.uint16_t,
|
||||
vol.Required(CONF_LOW): cv.uint16_t,
|
||||
vol.Required(CONF_HIGH): cv.uint16_t,
|
||||
vol.Required(CONF_DATA): validate_data,
|
||||
})
|
||||
|
||||
|
||||
def get_args(config):
|
||||
d = 0
|
||||
for v in config[CONF_DATA]:
|
||||
d <<= 1
|
||||
d |= v == '1'
|
||||
return [config[CONF_SYNC], config[CONF_LOW], config[CONF_HIGH], d]
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for uart in get_variable(config[CONF_UART_ID]):
|
||||
yield
|
||||
rhs = App.make_sonoff_rf_bridge(uart)
|
||||
Pvariable(config[CONF_ID], rhs)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_SONOFF_RF_BRIDGE'
|
18
esphomeyaml/components/switch/sonoff_rf_bridge.py
Normal file
18
esphomeyaml/components/switch/sonoff_rf_bridge.py
Normal file
@ -0,0 +1,18 @@
|
||||
from esphomeyaml.components import switch, sonoff_rf_bridge
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_NAME
|
||||
from esphomeyaml.helpers import get_variable, App
|
||||
|
||||
DEPENDENCIES = ['sonoff_rf_bridge']
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(sonoff_rf_bridge.CONF_SONOFF_RF_BRIDGE_ID):
|
||||
cv.use_variable_id(sonoff_rf_bridge.SonoffRFBridge)
|
||||
}).extend(sonoff_rf_bridge.FRAME_SCHEMA.schema))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for hub in get_variable(config[sonoff_rf_bridge.CONF_SONOFF_RF_BRIDGE_ID]):
|
||||
yield
|
||||
rhs = hub.Pmake_switch(config[CONF_NAME], *sonoff_rf_bridge.get_args(config))
|
||||
switch.register_switch(App.register_component(rhs), config)
|
@ -536,6 +536,12 @@ binary_sensor:
|
||||
number: 1
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
- platform: sonoff_rf_bridge
|
||||
name: Sonoff RF Bridge Binary Sensor
|
||||
sync: 100
|
||||
low: 100
|
||||
high: 100
|
||||
data: "01101110110101000010101010101011"
|
||||
|
||||
pca9685:
|
||||
frequency: 500
|
||||
@ -831,6 +837,12 @@ switch:
|
||||
- platform: uart
|
||||
name: "UART Bytes Output"
|
||||
data: [0xDE, 0xAD, 0xBE, 0xEF]
|
||||
- platform: sonoff_rf_bridge
|
||||
name: Sonoff RF Bridge Switch
|
||||
sync: 100
|
||||
low: 100
|
||||
high: 100
|
||||
data: "01101110110101000010101010101011"
|
||||
|
||||
fan:
|
||||
- platform: binary
|
||||
@ -941,3 +953,5 @@ pcf8574:
|
||||
- id: 'pcf8574_hub'
|
||||
address: 0x21
|
||||
pcf8575: False
|
||||
|
||||
sonoff_rf_bridge:
|
||||
|
Loading…
x
Reference in New Issue
Block a user