Skip to content

Commit

Permalink
Import util.dt as dt_util in components/[p-s]* (home-assistant#…
Browse files Browse the repository at this point in the history
  • Loading branch information
scop authored May 29, 2023
1 parent 2e59ae9 commit 940942a
Show file tree
Hide file tree
Showing 23 changed files with 111 additions and 109 deletions.
4 changes: 2 additions & 2 deletions tests/components/picnic/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
STATE_UNKNOWN,
)
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.util import dt
from homeassistant.util import dt as dt_util

from tests.common import (
MockConfigEntry,
Expand Down Expand Up @@ -177,7 +177,7 @@ async def _enable_all_sensors(self):
# Trigger a reload of the data
async_fire_time_changed(
self.hass,
dt.utcnow()
dt_util.utcnow()
+ timedelta(seconds=config_entries.RELOAD_AFTER_UPDATE_DELAY + 1),
)
await self.hass.async_block_till_done()
Expand Down
6 changes: 3 additions & 3 deletions tests/components/pjlink/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from homeassistant.util import dt
from homeassistant.util import dt as dt_util

from tests.common import assert_setup_component, async_fire_time_changed

Expand Down Expand Up @@ -206,7 +206,7 @@ async def test_update_unavailable(projector_from_address, hass: HomeAssistant) -
assert state.state == "off"

projector_from_address.side_effect = socket.timeout
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=10))
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done()

state = hass.states.get("media_player.test")
Expand Down Expand Up @@ -235,7 +235,7 @@ async def test_unavailable_time(mocked_projector, hass: HomeAssistant) -> None:
assert state.attributes["is_volume_muted"] is not False

mocked_projector.get_power.side_effect = ProjectorError("unavailable time")
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=10))
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done()

state = hass.states.get("media_player.test")
Expand Down
4 changes: 2 additions & 2 deletions tests/components/plex/test_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from homeassistant.components.plex.const import DEBOUNCE_TIMEOUT
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import HomeAssistant
from homeassistant.util import dt
from homeassistant.util import dt as dt_util

from tests.common import async_fire_time_changed

Expand All @@ -23,7 +23,7 @@ async def test_scan_clients_button_schedule(

async_fire_time_changed(
hass,
dt.utcnow() + timedelta(seconds=DEBOUNCE_TIMEOUT),
dt_util.utcnow() + timedelta(seconds=DEBOUNCE_TIMEOUT),
)

assert await hass.services.async_call(
Expand Down
10 changes: 5 additions & 5 deletions tests/components/plex/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.util import dt
from homeassistant.util import dt as dt_util

from .helpers import trigger_plex_update, wait_for_debouncer

Expand Down Expand Up @@ -125,7 +125,7 @@ async def test_library_sensor_values(

async_fire_time_changed(
hass,
dt.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
)

media = [MockPlexTVEpisode()]
Expand Down Expand Up @@ -196,7 +196,7 @@ async def test_library_sensor_values(

async_fire_time_changed(
hass,
dt.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
)

media = [MockPlexMovie()]
Expand All @@ -214,7 +214,7 @@ async def test_library_sensor_values(
async_dispatcher_send(
hass, PLEX_UPDATE_LIBRARY_SIGNAL.format(mock_plex_server.machine_identifier)
)
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=3))
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=3))
await hass.async_block_till_done()

library_movies_sensor = hass.states.get("sensor.plex_server_1_library_movies")
Expand All @@ -232,7 +232,7 @@ async def test_library_sensor_values(

async_fire_time_changed(
hass,
dt.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
)

media = [MockPlexMusic()]
Expand Down
24 changes: 12 additions & 12 deletions tests/components/recorder/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import homeassistant.core as ha
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import InvalidEntityFormatError
from homeassistant.util import dt, dt as dt_util
from homeassistant.util import dt as dt_util


def test_from_event_to_db_event() -> None:
Expand Down Expand Up @@ -85,7 +85,7 @@ def test_from_event_to_db_state_attributes() -> None:
def test_repr() -> None:
"""Test converting event to db state repr."""
attrs = {"this_attr": True}
fixed_time = datetime(2016, 7, 9, 11, 0, 0, tzinfo=dt.UTC, microsecond=432432)
fixed_time = datetime(2016, 7, 9, 11, 0, 0, tzinfo=dt_util.UTC, microsecond=432432)
state = ha.State(
"sensor.temperature",
"18",
Expand All @@ -105,7 +105,7 @@ def test_repr() -> None:

def test_states_repr_without_timestamp() -> None:
"""Test repr for a state without last_updated_ts."""
fixed_time = datetime(2016, 7, 9, 11, 0, 0, tzinfo=dt.UTC, microsecond=432432)
fixed_time = datetime(2016, 7, 9, 11, 0, 0, tzinfo=dt_util.UTC, microsecond=432432)
states = States(
entity_id="sensor.temp",
attributes=None,
Expand All @@ -123,7 +123,7 @@ def test_states_repr_without_timestamp() -> None:

def test_events_repr_without_timestamp() -> None:
"""Test repr for an event without time_fired_ts."""
fixed_time = datetime(2016, 7, 9, 11, 0, 0, tzinfo=dt.UTC, microsecond=432432)
fixed_time = datetime(2016, 7, 9, 11, 0, 0, tzinfo=dt_util.UTC, microsecond=432432)
events = Events(
event_type="any",
event_data=None,
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_states_from_native_invalid_entity_id() -> None:

async def test_process_timestamp() -> None:
"""Test processing time stamp to UTC."""
datetime_with_tzinfo = datetime(2016, 7, 9, 11, 0, 0, tzinfo=dt.UTC)
datetime_with_tzinfo = datetime(2016, 7, 9, 11, 0, 0, tzinfo=dt_util.UTC)
datetime_without_tzinfo = datetime(2016, 7, 9, 11, 0, 0)
est = dt_util.get_time_zone("US/Eastern")
datetime_est_timezone = datetime(2016, 7, 9, 11, 0, 0, tzinfo=est)
Expand All @@ -190,26 +190,26 @@ async def test_process_timestamp() -> None:
datetime_hst_timezone = datetime(2016, 7, 9, 11, 0, 0, tzinfo=hst)

assert process_timestamp(datetime_with_tzinfo) == datetime(
2016, 7, 9, 11, 0, 0, tzinfo=dt.UTC
2016, 7, 9, 11, 0, 0, tzinfo=dt_util.UTC
)
assert process_timestamp(datetime_without_tzinfo) == datetime(
2016, 7, 9, 11, 0, 0, tzinfo=dt.UTC
2016, 7, 9, 11, 0, 0, tzinfo=dt_util.UTC
)
assert process_timestamp(datetime_est_timezone) == datetime(
2016, 7, 9, 15, 0, tzinfo=dt.UTC
2016, 7, 9, 15, 0, tzinfo=dt_util.UTC
)
assert process_timestamp(datetime_nst_timezone) == datetime(
2016, 7, 9, 13, 30, tzinfo=dt.UTC
2016, 7, 9, 13, 30, tzinfo=dt_util.UTC
)
assert process_timestamp(datetime_hst_timezone) == datetime(
2016, 7, 9, 21, 0, tzinfo=dt.UTC
2016, 7, 9, 21, 0, tzinfo=dt_util.UTC
)
assert process_timestamp(None) is None


async def test_process_timestamp_to_utc_isoformat() -> None:
"""Test processing time stamp to UTC isoformat."""
datetime_with_tzinfo = datetime(2016, 7, 9, 11, 0, 0, tzinfo=dt.UTC)
datetime_with_tzinfo = datetime(2016, 7, 9, 11, 0, 0, tzinfo=dt_util.UTC)
datetime_without_tzinfo = datetime(2016, 7, 9, 11, 0, 0)
est = dt_util.get_time_zone("US/Eastern")
datetime_est_timezone = datetime(2016, 7, 9, 11, 0, 0, tzinfo=est)
Expand Down Expand Up @@ -409,7 +409,7 @@ async def test_process_datetime_to_timestamp_mirrors_utc_isoformat_behavior(
) -> None:
"""Test process_datetime_to_timestamp mirrors process_timestamp_to_utc_isoformat."""
hass.config.set_time_zone(time_zone)
datetime_with_tzinfo = datetime(2016, 7, 9, 11, 0, 0, tzinfo=dt.UTC)
datetime_with_tzinfo = datetime(2016, 7, 9, 11, 0, 0, tzinfo=dt_util.UTC)
datetime_without_tzinfo = datetime(2016, 7, 9, 11, 0, 0)
est = dt_util.get_time_zone("US/Eastern")
datetime_est_timezone = datetime(2016, 7, 9, 11, 0, 0, tzinfo=est)
Expand Down
6 changes: 3 additions & 3 deletions tests/components/risco/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.util import dt
from homeassistant.util import dt as dt_util

from tests.common import async_fire_time_changed

Expand Down Expand Up @@ -137,7 +137,7 @@ def _check_state(hass, category, entity_id):
event_index = CATEGORIES_TO_EVENTS[category]
event = TEST_EVENTS[event_index]
state = hass.states.get(entity_id)
assert state.state == dt.parse_datetime(event.time).isoformat()
assert state.state == dt_util.parse_datetime(event.time).isoformat()
assert state.attributes["category_id"] == event.category_id
assert state.attributes["category_name"] == event.category_name
assert state.attributes["type_id"] == event.type_id
Expand Down Expand Up @@ -192,7 +192,7 @@ async def test_cloud_setup(
"homeassistant.components.risco.Store.async_load",
return_value={LAST_EVENT_TIMESTAMP_KEY: TEST_EVENTS[0].time},
):
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=65))
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=65))
await hass.async_block_till_done()
events_mock.assert_awaited_once_with(TEST_EVENTS[0].time, 10)

Expand Down
4 changes: 2 additions & 2 deletions tests/components/sensibo/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.util import dt
from homeassistant.util import dt as dt_util

from tests.common import async_fire_time_changed

Expand Down Expand Up @@ -53,7 +53,7 @@ async def test_binary_sensor(
):
async_fire_time_changed(
hass,
dt.utcnow() + timedelta(minutes=5),
dt_util.utcnow() + timedelta(minutes=5),
)
await hass.async_block_till_done()

Expand Down
8 changes: 5 additions & 3 deletions tests/components/sensibo/test_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.util import dt
from homeassistant.util import dt as dt_util

from tests.common import async_fire_time_changed

Expand All @@ -35,7 +35,9 @@ async def test_button(
assert state_filter_clean.state is STATE_ON
assert state_filter_last_reset.state == "2022-03-12T15:24:26+00:00"

today = datetime(datetime.now().year + 1, 6, 19, 20, 0, 0).replace(tzinfo=dt.UTC)
today = datetime(datetime.now().year + 1, 6, 19, 20, 0, 0).replace(
tzinfo=dt_util.UTC
)
today_str = today.isoformat()
freezer.move_to(today)

Expand Down Expand Up @@ -69,7 +71,7 @@ async def test_button(
):
async_fire_time_changed(
hass,
dt.utcnow() + timedelta(minutes=5),
dt_util.utcnow() + timedelta(minutes=5),
)
await hass.async_block_till_done()

Expand Down
Loading

0 comments on commit 940942a

Please sign in to comment.