Skip to content

Commit

Permalink
Fix for single binary sensor and switch
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Ryl669 committed Mar 15, 2024
1 parent 806bc33 commit a710112
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 49 deletions.
16 changes: 8 additions & 8 deletions esphome/components/at581x/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

DEPENDENCIES = ["at581x"]

CONFIG_SCHEMA = (
binary_sensor.binary_sensor_schema(
device_class=DEVICE_CLASS_MOTION,
icon=ICON_MOTION_SENSOR,
).extend(cv.Schema(
CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(
device_class=DEVICE_CLASS_MOTION,
icon=ICON_MOTION_SENSOR,
).extend(
cv.Schema(
{
cv.GenerateID(CONF_AT581X_ID): cv.use_id(AT581XComponent),
}
)
)


async def to_code(config):
at581x_component = await cg.get_variable(config[CONF_AT581X_ID])
if has_target_config := config.get(CONF_HAS_TARGET):
sens = await binary_sensor.new_binary_sensor(has_target_config)
cg.add(at581x_component.set_motion_binary_sensor(sens))
sens = await binary_sensor.new_binary_sensor(config)
cg.add(at581x_component.set_motion_binary_sensor(sens))
32 changes: 15 additions & 17 deletions esphome/components/at581x/switch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,29 @@
import esphome.config_validation as cv
from esphome.const import (
DEVICE_CLASS_SWITCH,
ENTITY_CATEGORY_CONFIG,
ICON_BLUETOOTH,
ICON_WIFI,
)
from .. import CONF_AT581X_ID, AT581XComponent, at581x_ns

DEPENDENCIES = ["at581x"]

RFSwitch = at581x_ns.class_("RFSwitch", switch.Switch)

CONF_RF_POWER = "rf_power"

CONFIG_SCHEMA = {
cv.GenerateID(CONF_AT581X_ID): cv.use_id(AT581XComponent),
cv.Optional(CONF_RF_POWER): switch.switch_schema(
RFSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_BLUETOOTH,
),
}
CONFIG_SCHEMA = switch.switch_schema(
RFSwitch,
device_class=DEVICE_CLASS_SWITCH,
icon=ICON_WIFI,
).extend(
cv.Schema(
{
cv.GenerateID(CONF_AT581X_ID): cv.use_id(AT581XComponent),
}
)
)


async def to_code(config):
at581x_component = await cg.get_variable(config[CONF_AT581X_ID])
if rf_config := config.get(CONF_RF_POWER):
s = await switch.new_switch(rf_config)
await cg.register_parented(s, config[CONF_AT581X_ID])
cg.add(at581x_component.set_rf_power_switch(s))
s = await switch.new_switch(config)
await cg.register_parented(s, config[CONF_AT581X_ID])
cg.add(at581x_component.set_rf_power_switch(s))
6 changes: 2 additions & 4 deletions tests/components/at581x/test.esp32-c3-idf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ i2c:
binary_sensor:
- platform: at581x
at581x_id: "Waveradar"
has_target:
name: "Radar motion"
name: "Radar motion"

switch:
- platform: at581x
at581x_id: "Waveradar"
rf_power:
name: "Enable Radar"
name: "Enable Radar"
6 changes: 2 additions & 4 deletions tests/components/at581x/test.esp32-c3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ i2c:
binary_sensor:
- platform: at581x
at581x_id: "Waveradar"
has_target:
name: "Radar motion"
name: "Radar motion"

switch:
- platform: at581x
at581x_id: "Waveradar"
rf_power:
name: "Enable Radar"
name: "Enable Radar"
6 changes: 2 additions & 4 deletions tests/components/at581x/test.esp32-idf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ i2c:
binary_sensor:
- platform: at581x
at581x_id: "Waveradar"
has_target:
name: "Radar motion"
name: "Radar motion"

switch:
- platform: at581x
at581x_id: "Waveradar"
rf_power:
name: "Enable Radar"
name: "Enable Radar"
6 changes: 2 additions & 4 deletions tests/components/at581x/test.esp32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ i2c:
binary_sensor:
- platform: at581x
at581x_id: "Waveradar"
has_target:
name: "Radar motion"
name: "Radar motion"

switch:
- platform: at581x
at581x_id: "Waveradar"
rf_power:
name: "Enable Radar"
name: "Enable Radar"
6 changes: 2 additions & 4 deletions tests/components/at581x/test.esp8266.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ i2c:
binary_sensor:
- platform: at581x
at581x_id: "Waveradar"
has_target:
name: "Radar motion"
name: "Radar motion"

switch:
- platform: at581x
at581x_id: "Waveradar"
rf_power:
name: "Enable Radar"
name: "Enable Radar"
6 changes: 2 additions & 4 deletions tests/components/at581x/test.rp2040.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ i2c:
binary_sensor:
- platform: at581x
at581x_id: "Waveradar"
has_target:
name: "Radar motion"
name: "Radar motion"

switch:
- platform: at581x
at581x_id: "Waveradar"
rf_power:
name: "Enable Radar"
name: "Enable Radar"

0 comments on commit a710112

Please sign in to comment.