Skip to content

Commit

Permalink
Fix issue #184
Browse files Browse the repository at this point in the history
  • Loading branch information
rgc99 committed Sep 5, 2024
1 parent 65b1917 commit 05cd591
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
4 changes: 2 additions & 2 deletions custom_components/irrigation_unlimited/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ def remove_entity(entities: "dict[Entity]", entity_id: str) -> bool:
new_entities.append(
IUSequenceEntity(coordinator, controller, None, sequence)
)
for entity in old_entities:
await platform.async_remove_entity(entity)
if len(new_entities) > 0:
await platform.async_add_entities(new_entities)
coordinator.initialise()
for entity in old_entities:
await platform.async_remove_entity(entity)

return True

Expand Down
29 changes: 29 additions & 0 deletions tests/configs/service_reload_multi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
irrigation_unlimited:
controllers:
- name: "Front Yard Flowers SWV"
controller_id: frontyard_flowers_swv
zones:
- name: "Front Yard Flowers"
zone_id: flower_pots
schedules:
- time:
sun: "sunrise"
duration: "00:03:30"
- time: "15:00"
duration: "00:03:00"
rename_entities: true
testing:
enabled: true
speed: 1.0
output_events: true
show_log: false
autoplay: false
times:
- name: "1-Normal run"
start: "2024-09-05 06:00"
end: "2024-09-05 07:00"
results:
- {t: '2024-09-05 06:26:45', c: 1, z: 0, s: 1}
- {t: '2024-09-05 06:26:45', c: 1, z: 1, s: 1}
- {t: '2024-09-05 06:30:15', c: 1, z: 1, s: 0}
- {t: '2024-09-05 06:30:15', c: 1, z: 0, s: 0}
40 changes: 40 additions & 0 deletions tests/test_reload.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test integration_unlimited reload service calls."""

from datetime import timedelta
import pytest
import homeassistant.core as ha
Expand Down Expand Up @@ -237,3 +238,42 @@ async def test_service_reload_shrink_while_on(
# don't attempt to finish or check results, there are none.
# await exam.finish_test()
# check_summary(full_path)


async def test_service_reload_multi(hass: ha.HomeAssistant, skip_history):
"""Test reliablity on multiple reload calls"""

async with IUExam(hass, "service_reload_multi.yaml") as exam:
await exam.begin_test(1)
await exam.finish_test()
await exam.reload("service_reload_multi.yaml")
assert exam.coordinator.controllers[0].master_sensor is not None
assert exam.coordinator.controllers[0].zones[0].zone_sensor is not None
await exam.reload("service_reload_multi.yaml")
assert exam.coordinator.controllers[0].master_sensor is not None
assert exam.coordinator.controllers[0].zones[0].zone_sensor is not None
await exam.reload("service_reload_multi.yaml")
assert exam.coordinator.controllers[0].master_sensor is not None
assert exam.coordinator.controllers[0].zones[0].zone_sensor is not None
await exam.reload("service_reload_multi.yaml")
assert exam.coordinator.controllers[0].master_sensor is not None
assert exam.coordinator.controllers[0].zones[0].zone_sensor is not None
await exam.reload("service_reload_multi.yaml")
assert exam.coordinator.controllers[0].master_sensor is not None
assert exam.coordinator.controllers[0].zones[0].zone_sensor is not None
await exam.reload("service_reload_multi.yaml")
assert exam.coordinator.controllers[0].master_sensor is not None
assert exam.coordinator.controllers[0].zones[0].zone_sensor is not None
await exam.reload("service_reload_multi.yaml")
assert exam.coordinator.controllers[0].master_sensor is not None
assert exam.coordinator.controllers[0].zones[0].zone_sensor is not None
await exam.reload("service_reload_multi.yaml")
assert exam.coordinator.controllers[0].master_sensor is not None
assert exam.coordinator.controllers[0].zones[0].zone_sensor is not None
await exam.reload("service_reload_multi.yaml")
assert exam.coordinator.controllers[0].master_sensor is not None
assert exam.coordinator.controllers[0].zones[0].zone_sensor is not None
await exam.reload("service_reload_multi.yaml")
assert exam.coordinator.controllers[0].master_sensor is not None
assert exam.coordinator.controllers[0].zones[0].zone_sensor is not None
# exam.check_summary()

0 comments on commit 05cd591

Please sign in to comment.