Skip to content

Commit

Permalink
switch: only use PWM for PWM lights (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Habbie authored Feb 17, 2024
1 parent 1db5499 commit fcfc796
Show file tree
Hide file tree
Showing 3 changed files with 594 additions and 3 deletions.
7 changes: 4 additions & 3 deletions upk2esphome/parts/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@ def generate(yr: YamlResult, config: ConfigData, opts: Opts):
led_pin = None

if led_pin is not None:
yr.log(f" - LED {i}: pin P{led_pin}")
is_pwm = led_pin in (6, 7, 8, 9, 24, 26) # FIXME: this assumes BK7231
yr.log(f" - LED {i}: pin P{led_pin} (is_pwm={is_pwm})")
output = {
"platform": "libretiny_pwm",
"platform": "libretiny_pwm" if is_pwm else "gpio",
"id": f"output_led_{i}",
"pin": f"P{led_pin}",
}
invert(output, led_inv)
yr.output(output)
light = {
"platform": "monochromatic",
"platform": "monochromatic" if is_pwm else "binary",
"id": f"light_switch_{i}",
"output": output["id"],
}
Expand Down
60 changes: 60 additions & 0 deletions upk2esphome/tests/expected_output/plug_monitor_led_bl0937.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
output:
- platform: gpio
id: output_led_1
pin:
number: P10
inverted: true

light:
- platform: binary
id: light_switch_1
output: output_led_1

binary_sensor:
- platform: gpio
id: binary_switch_1
pin:
number: P11
inverted: true
mode: INPUT_PULLUP
on_press:
then:
- switch.toggle: switch_1

switch:
- platform: gpio
id: switch_1
name: Relay 1
pin: P26
on_turn_on:
- light.turn_on: light_switch_1
on_turn_off:
- light.turn_off: light_switch_1

status_led:
pin:
number: P8
inverted: true

sensor:
- platform: hlw8012
model: BL0937
cf_pin:
number: P7
inverted: true
cf1_pin:
number: P6
inverted: true
sel_pin:
number: P24
inverted: true
current:
name: BL0937 Current
voltage:
name: BL0937 Voltage
power:
name: BL0937 Power
energy:
name: BL0937 Energy
voltage_divider: 1600
current_resistor: 0.001 ohm
Loading

0 comments on commit fcfc796

Please sign in to comment.