mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Add mysensors device tracker tests (#84589)
This commit is contained in:
parent
0cebf1acb1
commit
941d175087
@ -801,7 +801,6 @@ omit =
|
||||
homeassistant/components/mysensors/const.py
|
||||
homeassistant/components/mysensors/cover.py
|
||||
homeassistant/components/mysensors/device.py
|
||||
homeassistant/components/mysensors/device_tracker.py
|
||||
homeassistant/components/mysensors/gateway.py
|
||||
homeassistant/components/mysensors/handler.py
|
||||
homeassistant/components/mysensors/helpers.py
|
||||
|
@ -213,7 +213,7 @@ def gps_sensor_state_fixture() -> dict:
|
||||
@pytest.fixture
|
||||
def gps_sensor(gateway_nodes: dict[int, Sensor], gps_sensor_state: dict) -> Sensor:
|
||||
"""Load the gps sensor."""
|
||||
nodes = update_gateway_nodes(gateway_nodes, gps_sensor_state)
|
||||
nodes = update_gateway_nodes(gateway_nodes, deepcopy(gps_sensor_state))
|
||||
node = nodes[1]
|
||||
return node
|
||||
|
||||
|
55
tests/components/mysensors/test_device_tracker.py
Normal file
55
tests/components/mysensors/test_device_tracker.py
Normal file
@ -0,0 +1,55 @@
|
||||
"""Provide tests for mysensors device tracker platform."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
|
||||
from mysensors.sensor import Sensor
|
||||
|
||||
from homeassistant.components.device_tracker import ATTR_SOURCE_TYPE, SourceType
|
||||
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, STATE_NOT_HOME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
async def test_gps_sensor(
|
||||
hass: HomeAssistant,
|
||||
gps_sensor: Sensor,
|
||||
receive_message: Callable[[str], None],
|
||||
) -> None:
|
||||
"""Test a gps sensor."""
|
||||
entity_id = "device_tracker.gps_sensor_1_1"
|
||||
altitude = 0
|
||||
latitude = "40.742"
|
||||
longitude = "-73.989"
|
||||
message_string = f"1;1;1;0;49;{latitude},{longitude},{altitude}\n"
|
||||
|
||||
receive_message(message_string)
|
||||
# the integration adds multiple jobs to do the update currently
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
|
||||
assert state
|
||||
assert state.state == STATE_NOT_HOME
|
||||
assert state.attributes[ATTR_SOURCE_TYPE] == SourceType.GPS
|
||||
assert state.attributes[ATTR_LATITUDE] == float(latitude)
|
||||
assert state.attributes[ATTR_LONGITUDE] == float(longitude)
|
||||
|
||||
latitude = "40.782"
|
||||
longitude = "-73.965"
|
||||
message_string = f"1;1;1;0;49;{latitude},{longitude},{altitude}\n"
|
||||
|
||||
receive_message(message_string)
|
||||
# the integration adds multiple jobs to do the update currently
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
|
||||
assert state
|
||||
assert state.state == STATE_NOT_HOME
|
||||
assert state.attributes[ATTR_SOURCE_TYPE] == SourceType.GPS
|
||||
assert state.attributes[ATTR_LATITUDE] == float(latitude)
|
||||
assert state.attributes[ATTR_LONGITUDE] == float(longitude)
|
Loading…
x
Reference in New Issue
Block a user