Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kellerza committed Jan 9, 2025
1 parent 19c32b4 commit 94e537d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/ha_addon_sunsynk_multi/sensor_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def init_sensors(self) -> None:
import_definitions()
self.clear()

self.startup = {DEFS.device_type, DEFS.rated_power, DEFS.serial}
self.startup = {DEFS.device_type, DEFS.serial}
sensors_all = list(get_sensors(target=self, names=OPT.sensors))
sensors_1st = list(get_sensors(target=self, names=OPT.sensors_first_inverter))

Expand Down
2 changes: 2 additions & 0 deletions src/tests/ha_addon_sunsynk_multi/test_sensor_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ async def test_build_callback_schedule(ist: AInverter) -> None:
SensorOption(
sensor=Sensor(1, name="test", unit="kWh"),
schedule=Schedule(read_every=1, report_every=10),
visible=True,
),
SensorOption(
sensor=Sensor(2, name="test2", unit="kWh"),
schedule=Schedule(read_every=1, report_every=20),
visible=True,
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,25 @@
def test_opt1() -> None:
"""Sensors."""
SOPT.init_sensors()
assert sorted(s.id for s in SOPT.startup) == ["rated_power", "serial"]
assert sorted(s.id for s in SOPT) == ["rated_power", "serial"]
assert sorted(s.id for s in SOPT.startup) == ["device_type", "serial"]
assert sorted(s.id for s in SOPT) == ["device_type", "serial"]

OPT.sensors = ["prog1_time"]
SOPT.init_sensors()
assert sorted(s.id for s in SOPT.startup) == [
"device_type",
"serial",
]
assert sorted(s.id for s in SOPT) == [
"device_type",
"prog1_time",
"prog2_time",
"prog3_time",
"prog4_time",
"prog5_time",
"prog6_time",
"rated_power",
"serial",
]
assert sorted(s.id for s in SOPT) == [
assert sorted(s.id for s in SOPT if SOPT[s].visible) == [
"prog1_time",
"prog2_time",
"prog6_time",
"rated_power",
"serial",
]
# assert SOPT.filter_str == {
# "prog1_time": "round_robin",
# "prog2_time": "round_robin",
# "prog6_time": "round_robin",
# }
# assert SOPT["prog1_time"].visible
12 changes: 9 additions & 3 deletions src/tests/ha_addon_sunsynk_multi/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ def test_create_entity(mqtt_device: Device, ist: AInverter) -> None:
STATE.append(ist)

st = ASensor(
opt=SensorOption(sensor=Sensor(1, "one", "W"), schedule=NOSCHEDULE),
opt=SensorOption(
sensor=Sensor(1, "one", "W"), schedule=NOSCHEDULE, visible=True
),
)

assert st.name == "one"

# Create the mqtt entity
ent: Entity = st.create_entity(dev=mqtt_device, ist=ist)
ent: Entity = st.create_entity(mqtt_device, ist=ist)
entd: dict = ent.asdict
assert entd == {
"device": {"identifiers": ["888"]},
Expand All @@ -49,7 +51,11 @@ def test_create_entity2(mqtt_device: Device, ist: AInverter) -> None:

STATE.append(ist)

st = ASensor(opt=SensorOption(sensor=Sensor(1, nme, "kWh"), schedule=NOSCHEDULE))
st = ASensor(
opt=SensorOption(
sensor=Sensor(1, nme, "kWh"), schedule=NOSCHEDULE, visible=True
)
)

# Create the mqtt entity
ent: Entity = st.create_entity(mqtt_device, ist=ist)
Expand Down

0 comments on commit 94e537d

Please sign in to comment.