-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest_cover_state.py
More file actions
83 lines (70 loc) · 2.85 KB
/
test_cover_state.py
File metadata and controls
83 lines (70 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""Test cover state and transitions."""
from unittest.mock import MagicMock
import pytest
from homeassistant.const import STATE_CLOSED, STATE_OPEN, STATE_OPENING, STATE_CLOSING
from homeassistant.components.cover import CoverDeviceClass
from custom_components.tuiss2ha.cover import Tuiss
@pytest.mark.parametrize("moving,position,expected_state", [
(0, 0, STATE_CLOSED), # not moving, position 0
(0, 24, STATE_CLOSED), # not moving, position < 25
(0, 25, STATE_OPEN), # not moving, position = 25
(0, 50, STATE_OPEN), # not moving, position > 25
(0, 100, STATE_OPEN), # not moving, position = 100
(1, 50, STATE_OPENING), # moving up
(-1, 50, STATE_CLOSING), # moving down
])
def test_cover_state_transitions(mock_hass, moving, position, expected_state):
"""Test cover entity state property based on _moving and position values."""
# Create a fake blind
blind = MagicMock()
blind._moving = moving
blind._current_cover_position = position
blind.name = "Test Blind"
blind.model = "TB-01"
blind.blind_id = "aa:bb:cc:dd:ee:ff"
blind.host = blind.blind_id
blind.hub = MagicMock(manufacturer="Tuiss")
# Create a fake config entry
config = MagicMock()
config.options = {}
cover = Tuiss(blind, config)
assert cover.state == expected_state
@pytest.mark.parametrize("position,expected_closed", [
(0, True), # position 0 is closed
(1, False), # position > 0 is not closed
(50, False), # middle position is not closed
(100, False), # fully open is not closed
(None, None), # None position returns None
])
def test_cover_is_closed_property(mock_hass, position, expected_closed):
"""Test is_closed property based on current position."""
blind = MagicMock()
blind._current_cover_position = position
blind.name = "Test Blind"
blind.model = "TB-01"
blind.blind_id = "aa:bb:cc:dd:ee:ff"
blind.host = blind.blind_id
blind.hub = MagicMock(manufacturer="Tuiss")
config = MagicMock()
config.options = {}
cover = Tuiss(blind, config)
assert cover.is_closed is expected_closed
def test_cover_properties(mock_hass):
"""Test basic cover properties."""
blind = MagicMock()
blind.name = "Test Blind"
blind.model = "TB-01"
blind.blind_id = "aa:bb:cc:dd:ee:ff"
blind.host = blind.blind_id
blind.hub = MagicMock(manufacturer="Tuiss")
blind._attr_traversal_speed = 5.0
config = MagicMock()
config.options = {}
cover = Tuiss(blind, config)
assert cover.device_class == CoverDeviceClass.SHADE
assert cover.available is True
assert cover.should_poll is False
assert cover._attr_name == "Test Blind"
assert cover._attr_unique_id == "aa:bb:cc:dd:ee:ff_cover"
assert "traversal_speed" in cover.extra_state_attributes
assert "mac_address" in cover.extra_state_attributes