Skip to content

Commit

Permalink
Cleanup SourceType in tests (#78809)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed Sep 20, 2022
1 parent 25b1dfb commit 4f31f28
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 34 deletions.
4 changes: 2 additions & 2 deletions tests/components/device_tracker/test_entities.py
Expand Up @@ -11,7 +11,7 @@
ATTR_MAC,
ATTR_SOURCE_TYPE,
DOMAIN,
SOURCE_TYPE_ROUTER,
SourceType,
)
from homeassistant.const import ATTR_BATTERY_LEVEL, STATE_HOME, STATE_NOT_HOME
from homeassistant.helpers import device_registry as dr
Expand All @@ -37,7 +37,7 @@ async def test_scanner_entity_device_tracker(hass, enable_custom_integrations):
entity_id = "device_tracker.test_ad_de_ef_be_ed_fe"
entity_state = hass.states.get(entity_id)
assert entity_state.attributes == {
ATTR_SOURCE_TYPE: SOURCE_TYPE_ROUTER,
ATTR_SOURCE_TYPE: SourceType.ROUTER,
ATTR_BATTERY_LEVEL: 100,
ATTR_IP: "0.0.0.0",
ATTR_MAC: "ad:de:ef:be:ed:fe",
Expand Down
6 changes: 3 additions & 3 deletions tests/components/device_tracker/test_init.py
Expand Up @@ -9,7 +9,7 @@

from homeassistant.components import zone
import homeassistant.components.device_tracker as device_tracker
from homeassistant.components.device_tracker import const, legacy
from homeassistant.components.device_tracker import SourceType, const, legacy
from homeassistant.const import (
ATTR_ENTITY_PICTURE,
ATTR_FRIENDLY_NAME,
Expand Down Expand Up @@ -495,7 +495,7 @@ async def test_see_passive_zone_state(
assert attrs.get("latitude") == 1
assert attrs.get("longitude") == 2
assert attrs.get("gps_accuracy") == 0
assert attrs.get("source_type") == device_tracker.SOURCE_TYPE_ROUTER
assert attrs.get("source_type") == SourceType.ROUTER

scanner.leave_home("dev1")

Expand All @@ -515,7 +515,7 @@ async def test_see_passive_zone_state(
assert attrs.get("latitude") is None
assert attrs.get("longitude") is None
assert attrs.get("gps_accuracy") is None
assert attrs.get("source_type") == device_tracker.SOURCE_TYPE_ROUTER
assert attrs.get("source_type") == SourceType.ROUTER


@patch("homeassistant.components.device_tracker.const.LOGGER.warning")
Expand Down
12 changes: 6 additions & 6 deletions tests/components/dhcp/test_init.py
Expand Up @@ -16,7 +16,7 @@
ATTR_MAC,
ATTR_SOURCE_TYPE,
CONNECTED_DEVICE_REGISTERED,
SOURCE_TYPE_ROUTER,
SourceType,
)
from homeassistant.components.dhcp.const import DOMAIN
from homeassistant.const import (
Expand Down Expand Up @@ -603,7 +603,7 @@ async def test_device_tracker_hostname_and_macaddress_exists_before_start(hass):
{
ATTR_HOST_NAME: "Connect",
ATTR_IP: "192.168.210.56",
ATTR_SOURCE_TYPE: SOURCE_TYPE_ROUTER,
ATTR_SOURCE_TYPE: SourceType.ROUTER,
ATTR_MAC: "B8:B7:F1:6D:B5:33",
},
)
Expand Down Expand Up @@ -701,7 +701,7 @@ async def test_device_tracker_hostname_and_macaddress_after_start(hass):
{
ATTR_HOST_NAME: "Connect",
ATTR_IP: "192.168.210.56",
ATTR_SOURCE_TYPE: SOURCE_TYPE_ROUTER,
ATTR_SOURCE_TYPE: SourceType.ROUTER,
ATTR_MAC: "B8:B7:F1:6D:B5:33",
},
)
Expand Down Expand Up @@ -738,7 +738,7 @@ async def test_device_tracker_hostname_and_macaddress_after_start_not_home(hass)
{
ATTR_HOST_NAME: "connect",
ATTR_IP: "192.168.210.56",
ATTR_SOURCE_TYPE: SOURCE_TYPE_ROUTER,
ATTR_SOURCE_TYPE: SourceType.ROUTER,
ATTR_MAC: "B8:B7:F1:6D:B5:33",
},
)
Expand Down Expand Up @@ -795,7 +795,7 @@ async def test_device_tracker_hostname_and_macaddress_after_start_hostname_missi
STATE_HOME,
{
ATTR_IP: "192.168.210.56",
ATTR_SOURCE_TYPE: SOURCE_TYPE_ROUTER,
ATTR_SOURCE_TYPE: SourceType.ROUTER,
ATTR_MAC: "B8:B7:F1:6D:B5:33",
},
)
Expand All @@ -814,7 +814,7 @@ async def test_device_tracker_ignore_self_assigned_ips_before_start(hass):
{
ATTR_HOST_NAME: "connect",
ATTR_IP: "169.254.210.56",
ATTR_SOURCE_TYPE: SOURCE_TYPE_ROUTER,
ATTR_SOURCE_TYPE: SourceType.ROUTER,
ATTR_MAC: "B8:B7:F1:6D:B5:33",
},
)
Expand Down
4 changes: 2 additions & 2 deletions tests/components/mazda/test_device_tracker.py
@@ -1,5 +1,5 @@
"""The device tracker tests for the Mazda Connected Services integration."""
from homeassistant.components.device_tracker import ATTR_SOURCE_TYPE, SOURCE_TYPE_GPS
from homeassistant.components.device_tracker import ATTR_SOURCE_TYPE, SourceType
from homeassistant.const import (
ATTR_FRIENDLY_NAME,
ATTR_ICON,
Expand All @@ -23,7 +23,7 @@ async def test_device_tracker(hass):
assert state.attributes.get(ATTR_ICON) == "mdi:car"
assert state.attributes.get(ATTR_LATITUDE) == 1.234567
assert state.attributes.get(ATTR_LONGITUDE) == -2.345678
assert state.attributes.get(ATTR_SOURCE_TYPE) == SOURCE_TYPE_GPS
assert state.attributes.get(ATTR_SOURCE_TYPE) == SourceType.GPS
entry = entity_registry.async_get("device_tracker.my_mazda3_device_tracker")
assert entry
assert entry.unique_id == "JM000000000000000"
26 changes: 7 additions & 19 deletions tests/components/person/test_init.py
Expand Up @@ -5,11 +5,7 @@
import pytest

from homeassistant.components import person
from homeassistant.components.device_tracker import (
ATTR_SOURCE_TYPE,
SOURCE_TYPE_GPS,
SOURCE_TYPE_ROUTER,
)
from homeassistant.components.device_tracker import ATTR_SOURCE_TYPE, SourceType
from homeassistant.components.person import ATTR_SOURCE, ATTR_USER_ID, DOMAIN
from homeassistant.const import (
ATTR_ENTITY_PICTURE,
Expand Down Expand Up @@ -208,9 +204,7 @@ async def test_setup_two_trackers(hass, hass_admin_user):

hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
hass.states.async_set(
DEVICE_TRACKER, "home", {ATTR_SOURCE_TYPE: SOURCE_TYPE_ROUTER}
)
hass.states.async_set(DEVICE_TRACKER, "home", {ATTR_SOURCE_TYPE: SourceType.ROUTER})
await hass.async_block_till_done()

state = hass.states.get("person.tracked_person")
Expand All @@ -229,12 +223,12 @@ async def test_setup_two_trackers(hass, hass_admin_user):
ATTR_LATITUDE: 12.123456,
ATTR_LONGITUDE: 13.123456,
ATTR_GPS_ACCURACY: 12,
ATTR_SOURCE_TYPE: SOURCE_TYPE_GPS,
ATTR_SOURCE_TYPE: SourceType.GPS,
},
)
await hass.async_block_till_done()
hass.states.async_set(
DEVICE_TRACKER, "not_home", {ATTR_SOURCE_TYPE: SOURCE_TYPE_ROUTER}
DEVICE_TRACKER, "not_home", {ATTR_SOURCE_TYPE: SourceType.ROUTER}
)
await hass.async_block_till_done()

Expand All @@ -247,22 +241,16 @@ async def test_setup_two_trackers(hass, hass_admin_user):
assert state.attributes.get(ATTR_SOURCE) == DEVICE_TRACKER_2
assert state.attributes.get(ATTR_USER_ID) == user_id

hass.states.async_set(
DEVICE_TRACKER_2, "zone1", {ATTR_SOURCE_TYPE: SOURCE_TYPE_GPS}
)
hass.states.async_set(DEVICE_TRACKER_2, "zone1", {ATTR_SOURCE_TYPE: SourceType.GPS})
await hass.async_block_till_done()

state = hass.states.get("person.tracked_person")
assert state.state == "zone1"
assert state.attributes.get(ATTR_SOURCE) == DEVICE_TRACKER_2

hass.states.async_set(
DEVICE_TRACKER, "home", {ATTR_SOURCE_TYPE: SOURCE_TYPE_ROUTER}
)
hass.states.async_set(DEVICE_TRACKER, "home", {ATTR_SOURCE_TYPE: SourceType.ROUTER})
await hass.async_block_till_done()
hass.states.async_set(
DEVICE_TRACKER_2, "zone2", {ATTR_SOURCE_TYPE: SOURCE_TYPE_GPS}
)
hass.states.async_set(DEVICE_TRACKER_2, "zone2", {ATTR_SOURCE_TYPE: SourceType.GPS})
await hass.async_block_till_done()

state = hass.states.get("person.tracked_person")
Expand Down
4 changes: 2 additions & 2 deletions tests/components/zha/test_device_tracker.py
Expand Up @@ -7,7 +7,7 @@
import zigpy.profiles.zha
import zigpy.zcl.clusters.general as general

from homeassistant.components.device_tracker import SOURCE_TYPE_ROUTER
from homeassistant.components.device_tracker import SourceType
from homeassistant.components.zha.core.registries import (
SMARTTHINGS_ARRIVAL_SENSOR_DEVICE_TYPE,
)
Expand Down Expand Up @@ -101,7 +101,7 @@ async def test_device_tracker(hass, zha_device_joined_restored, zigpy_device_dt)
entity = hass.data[Platform.DEVICE_TRACKER].get_entity(entity_id)

assert entity.is_connected is True
assert entity.source_type == SOURCE_TYPE_ROUTER
assert entity.source_type == SourceType.ROUTER
assert entity.battery_level == 100

# test adding device tracker to the network and HA
Expand Down

0 comments on commit 4f31f28

Please sign in to comment.