Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verify yaml output #9

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/check-output.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Check ESPHome YAML output
on:
push:
branches: ["**"]
pull_request:
jobs:
check-output:
name: Verify YAML output
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- run: python3 -m upk2esphome.test
17 changes: 16 additions & 1 deletion upk2esphome/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import sys
from glob import glob
from os.path import dirname, isfile, join
from os.path import basename, dirname, isfile, join

from .generator import upk2esphome
from .opts import Opts
Expand All @@ -20,6 +20,8 @@

mask = "*.txt"

errors = []

for file in glob(join(dirname(__file__), "tests", mask)):
if len(sys.argv) == 2 and sys.argv[1] not in file:
continue
Expand All @@ -39,3 +41,16 @@
print("\n".join(f"E: {s}" for s in yr.errors))
print(yr.text)
print("-" * 80)

expected = join(
dirname(__file__), "tests", "expected_output", basename(file)
).replace(".txt", ".yaml")
with open(expected, "r") as f:
expected_yaml = f.read()
if expected_yaml != yr.text:
errors.append(f"content of {expected} was not as expected")

if errors:
print("got errors:")
print("\n".join(errors))
sys.exit(1)
16 changes: 16 additions & 0 deletions upk2esphome/tests/expected_output/bulb_pwm_ct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
output:
- platform: libretiny_pwm
id: output_brightness
pin: P8
- platform: libretiny_pwm
id: output_temperature
pin: P7

light:
- platform: color_temperature
id: light_color_temperature
name: Light
cold_white_color_temperature: 6500 K
warm_white_color_temperature: 2700 K
brightness: output_brightness
color_temperature: output_temperature
16 changes: 16 additions & 0 deletions upk2esphome/tests/expected_output/bulb_pwm_cw.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
output:
- platform: libretiny_pwm
id: output_cold
pin: P7
- platform: libretiny_pwm
id: output_warm
pin: P6

light:
- platform: cwww
id: light_cwww
name: Light
cold_white_color_temperature: 6500 K
warm_white_color_temperature: 2700 K
cold_white: output_cold
warm_white: output_warm
29 changes: 29 additions & 0 deletions upk2esphome/tests/expected_output/bulb_pwm_rgbct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
output:
- platform: libretiny_pwm
id: output_red
pin: P24
- platform: libretiny_pwm
id: output_green
pin: P9
- platform: libretiny_pwm
id: output_blue
pin: P26
- platform: libretiny_pwm
id: output_brightness
pin: P7
- platform: libretiny_pwm
id: output_temperature
pin: P8

light:
- platform: rgbct
id: light_rgbct
name: Light
color_interlock: true
cold_white_color_temperature: 6500 K
warm_white_color_temperature: 2700 K
red: output_red
green: output_green
blue: output_blue
white_brightness: output_brightness
color_temperature: output_temperature
29 changes: 29 additions & 0 deletions upk2esphome/tests/expected_output/bulb_pwm_rgbcw.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
output:
- platform: libretiny_pwm
id: output_red
pin: P6
- platform: libretiny_pwm
id: output_green
pin: P26
- platform: libretiny_pwm
id: output_blue
pin: P24
- platform: libretiny_pwm
id: output_cold
pin: P7
- platform: libretiny_pwm
id: output_warm
pin: P8

light:
- platform: rgbww
id: light_rgbww
name: Light
color_interlock: true
cold_white_color_temperature: 6500 K
warm_white_color_temperature: 2700 K
red: output_red
green: output_green
blue: output_blue
cold_white: output_cold
warm_white: output_warm
28 changes: 28 additions & 0 deletions upk2esphome/tests/expected_output/bulb_rgbc_2135_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
sm2135:
clock_pin: P8
data_pin: P7
rgb_current: 30mA
cw_current: 45mA

output:
- platform: sm2135
id: output_red
channel: 2
- platform: sm2135
id: output_green
channel: 1
- platform: sm2135
id: output_blue
channel: 0
- platform: sm2135
id: output_cold
channel: 3

light:
- platform: rgbw
id: light_rgbw
name: Light
red: output_red
green: output_green
blue: output_blue
white: output_cold
35 changes: 35 additions & 0 deletions upk2esphome/tests/expected_output/bulb_rgbcw_2135.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
sm2135:
clock_pin: P7
data_pin: P9
rgb_current: 40mA
cw_current: 25mA

output:
- platform: sm2135
id: output_red
channel: 2
- platform: sm2135
id: output_green
channel: 1
- platform: sm2135
id: output_blue
channel: 0
- platform: sm2135
id: output_cold
channel: 4
- platform: sm2135
id: output_warm
channel: 3

light:
- platform: rgbww
id: light_rgbww
name: Light
color_interlock: true
cold_white_color_temperature: 6500 K
warm_white_color_temperature: 2700 K
red: output_red
green: output_green
blue: output_blue
cold_white: output_cold
warm_white: output_warm
35 changes: 35 additions & 0 deletions upk2esphome/tests/expected_output/bulb_rgbcw_2135_ampere.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
sm2135:
clock_pin: P8
data_pin: P26
rgb_current: 20mA
cw_current: 50mA

output:
- platform: sm2135
id: output_red
channel: 2
- platform: sm2135
id: output_green
channel: 1
- platform: sm2135
id: output_blue
channel: 0
- platform: sm2135
id: output_cold
channel: 4
- platform: sm2135
id: output_warm
channel: 3

light:
- platform: rgbww
id: light_rgbww
name: Light
color_interlock: true
cold_white_color_temperature: 6500 K
warm_white_color_temperature: 2700 K
red: output_red
green: output_green
blue: output_blue
cold_white: output_cold
warm_white: output_warm
35 changes: 35 additions & 0 deletions upk2esphome/tests/expected_output/bulb_rgbcw_2235.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
sm2235:
clock_pin: P26
data_pin: P24
max_power_color_channels: 1
max_power_white_channels: 2

output:
- platform: sm2235
id: output_red
channel: 1
- platform: sm2235
id: output_green
channel: 0
- platform: sm2235
id: output_blue
channel: 2
- platform: sm2235
id: output_cold
channel: 4
- platform: sm2235
id: output_warm
channel: 3

light:
- platform: rgbww
id: light_rgbww
name: Light
color_interlock: true
cold_white_color_temperature: 6500 K
warm_white_color_temperature: 2700 K
red: output_red
green: output_green
blue: output_blue
cold_white: output_cold
warm_white: output_warm
38 changes: 38 additions & 0 deletions upk2esphome/tests/expected_output/bulb_rgbcw_5758d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
bp5758d:
clock_pin: P24
data_pin: P26

output:
- platform: bp5758d
id: output_red
channel: 2
current: 14
- platform: bp5758d
id: output_green
channel: 1
current: 14
- platform: bp5758d
id: output_blue
channel: 3
current: 14
- platform: bp5758d
id: output_cold
channel: 5
current: 26
- platform: bp5758d
id: output_warm
channel: 4
current: 26

light:
- platform: rgbww
id: light_rgbww
name: Light
color_interlock: true
cold_white_color_temperature: 6500 K
warm_white_color_temperature: 2700 K
red: output_red
green: output_green
blue: output_blue
cold_white: output_cold
warm_white: output_warm
1 change: 1 addition & 0 deletions upk2esphome/tests/expected_output/empty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

44 changes: 44 additions & 0 deletions upk2esphome/tests/expected_output/plug_monitor_bl0937.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
binary_sensor:
- platform: gpio
id: binary_switch_1
pin:
number: P10
inverted: true
mode: INPUT_PULLUP
on_press:
then:
- switch.toggle: switch_1

switch:
- platform: gpio
id: switch_1
name: Relay 1
pin: P26

status_led:
pin:
number: P6
inverted: true

sensor:
- platform: hlw8012
model: BL0937
cf_pin:
number: P7
inverted: true
cf1_pin:
number: P8
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
Loading