mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Add mysensors binary sensor tests (#84580)
This commit is contained in:
parent
cf92d8c536
commit
101118a60e
@ -797,7 +797,6 @@ omit =
|
||||
homeassistant/components/myq/cover.py
|
||||
homeassistant/components/myq/light.py
|
||||
homeassistant/components/mysensors/__init__.py
|
||||
homeassistant/components/mysensors/binary_sensor.py
|
||||
homeassistant/components/mysensors/climate.py
|
||||
homeassistant/components/mysensors/const.py
|
||||
homeassistant/components/mysensors/cover.py
|
||||
|
@ -2,6 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import AsyncGenerator, Callable, Generator
|
||||
from copy import deepcopy
|
||||
import json
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
@ -189,6 +190,20 @@ def update_gateway_nodes(
|
||||
return nodes
|
||||
|
||||
|
||||
@pytest.fixture(name="door_sensor_state", scope="session")
|
||||
def door_sensor_state_fixture() -> dict:
|
||||
"""Load the door sensor state."""
|
||||
return load_nodes_state("mysensors/door_sensor_state.json")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def door_sensor(gateway_nodes: dict[int, Sensor], door_sensor_state: dict) -> Sensor:
|
||||
"""Load the door sensor."""
|
||||
nodes = update_gateway_nodes(gateway_nodes, deepcopy(door_sensor_state))
|
||||
node = nodes[1]
|
||||
return node
|
||||
|
||||
|
||||
@pytest.fixture(name="gps_sensor_state", scope="session")
|
||||
def gps_sensor_state_fixture() -> dict:
|
||||
"""Load the gps sensor state."""
|
||||
|
21
tests/components/mysensors/fixtures/door_sensor_state.json
Normal file
21
tests/components/mysensors/fixtures/door_sensor_state.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"1": {
|
||||
"sensor_id": 1,
|
||||
"children": {
|
||||
"1": {
|
||||
"id": 1,
|
||||
"type": 0,
|
||||
"description": "",
|
||||
"values": {
|
||||
"16": "0"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": 17,
|
||||
"sketch_name": "Door Sensor",
|
||||
"sketch_version": "1.0",
|
||||
"battery_level": 0,
|
||||
"protocol_version": "2.3.2",
|
||||
"heartbeat": 0
|
||||
}
|
||||
}
|
49
tests/components/mysensors/test_binary_sensor.py
Normal file
49
tests/components/mysensors/test_binary_sensor.py
Normal file
@ -0,0 +1,49 @@
|
||||
"""Provide tests for mysensors binary sensor platform."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from mysensors.sensor import Sensor
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
|
||||
from homeassistant.const import ATTR_DEVICE_CLASS
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
async def test_door_sensor(
|
||||
hass: HomeAssistant,
|
||||
door_sensor: Sensor,
|
||||
receive_message: Callable[[str], None],
|
||||
transport_write: MagicMock,
|
||||
) -> None:
|
||||
"""Test a door sensor."""
|
||||
entity_id = "binary_sensor.door_sensor_1_1"
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
|
||||
assert state
|
||||
assert state.state == "off"
|
||||
assert state.attributes[ATTR_DEVICE_CLASS] == BinarySensorDeviceClass.DOOR
|
||||
|
||||
receive_message("1;1;1;0;16;1\n")
|
||||
# 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 == "on"
|
||||
|
||||
receive_message("1;1;1;0;16;0\n")
|
||||
# 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 == "off"
|
Loading…
x
Reference in New Issue
Block a user