Skip to content

Commit

Permalink
Fix again
Browse files Browse the repository at this point in the history
  • Loading branch information
pnbruckner committed Mar 9, 2024
1 parent c7813da commit 7de7d61
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ async def test_yaml_binary_sensor(
config["binary_sensors"][0]["name"] = name

tz = dt_util.get_time_zone(NY_CONFIG["time_zone"])
base_time = dt_util.now().astimezone(tz)
base_time = dt_util.now(tz)
print("tz", tz, "base_time", base_time, "local", datetime.now(), "dt_util.now()", dt_util.now())

# Set time to 00:00:00 tommorow.
now = datetime.combine((base_time + timedelta(1)).date(), time()).astimezone(tz)
now = datetime.combine((base_time + timedelta(1)).date(), time()).replace(tzinfo=tz)
print("now", now)

with patch("homeassistant.util.dt.now", return_value=now):
print(dt_util.now())
print("dt_util.now()", dt_util.now())
with assert_setup_component(1, DOMAIN):
await async_setup_component(hass, DOMAIN, {DOMAIN: [config]})
await hass.async_block_till_done()
Expand All @@ -77,6 +79,7 @@ async def test_yaml_binary_sensor(
# Next change should be after midnight and before noon.
next_change = state.attributes.get("next_change")
noon = now.replace(hour=12)
print("next_change", next_change, "noon", noon)
assert isinstance(next_change, datetime)
assert now < next_change < noon

Expand Down

0 comments on commit 7de7d61

Please sign in to comment.