Skip to content

Commit

Permalink
Support shared status LED
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Aug 28, 2023
1 parent 0af4ef5 commit 04866f3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
26 changes: 19 additions & 7 deletions upk2esphome/parts/netled.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,32 @@
def generate(yr: YamlResult, config: dict, opts: Opts):
keys = ["netled", "netled1", "wfst"]

netled_reuse = config.get("netled_reuse", None) == 1

found = False
for key in keys:
led_pin = config.get(f"{key}_pin")
led_inv = config.get(f"{key}_pin", None) == 0
led_inv = config.get(f"{key}_lv", None) == 0
if led_pin is None:
continue
if found:
yr.warn("Multiple netled pins found!")
continue
found = True

yr.log(f"Status LED: pin P{led_pin}, inverted {led_inv}")
status_led = {
"pin": f"P{led_pin}",
}
invert(status_led, led_inv)
yr.data["status_led"] = status_led
if netled_reuse:
yr.log(f"Status LED: pin P{led_pin} (shared), inverted {led_inv}")
light = {
"platform": "status_led",
"id": f"light_status",
"pin": f"P{led_pin}",
}
invert(light, led_inv)
yr.light(light)
else:
yr.log(f"Status LED: pin P{led_pin}, inverted {led_inv}")
status_led = {
"pin": f"P{led_pin}",
}
invert(status_led, led_inv)
yr.data["status_led"] = status_led
10 changes: 10 additions & 0 deletions upk2esphome/parts/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def generate(yr: YamlResult, config: dict, opts: Opts):
return
yr.log("Switch/plug config")

netled_reuse = config.get("netled_reuse", None) == 1

switches = []
for i in range(0, 10):
rl_pin = config.get(f"rl{i}_pin", None)
Expand Down Expand Up @@ -66,6 +68,14 @@ def generate(yr: YamlResult, config: dict, opts: Opts):
switch["on_turn_off"] = [
{"light.turn_off": light["id"]},
]
elif netled_reuse:
yr.log(f" - LED {i}: (shared)")
switch["on_turn_on"] = [
{"light.turn_on": "light_status"},
]
switch["on_turn_off"] = [
{"light.turn_off": "light_status"},
]

if bt_pin is not None:
yr.log(f" - button {i}: pin P{bt_pin}")
Expand Down
32 changes: 32 additions & 0 deletions upk2esphome/tests/plug_netled_reuse.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"bt1_lv": 0,
"bt1_pin": 23,
"bt1_type": 0,
"ch1_stat": 0,
"ch_cddpid1": 9,
"ch_dpid1": 1,
"ch_num": 1,
"chip_type": 0,
"crc": 32,
"ele_fun_en": 1,
"ele_pin": 7,
"ffc_select": 1,
"jv": "1.0.5",
"lose_vol": 0,
"module": "CB2S",
"net_trig": 4,
"netled1_lv": 0,
"netled1_pin": 8,
"netled_reuse": 1,
"over_cur": 21000,
"over_vol": 0,
"reset_t": 5,
"resistor": 1,
"rl1_lv": 1,
"rl1_pin": 26,
"rl1_type": 0,
"sel_pin_lv": 1,
"sel_pin_pin": 24,
"vi_pin": 6,
"vol_def": 0
}

0 comments on commit 04866f3

Please sign in to comment.