-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_dab.py
150 lines (115 loc) · 4.22 KB
/
test_dab.py
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import pytest
from ynca import BandDab
from ynca.enums import DabPreset, FmPreset
from ynca.subunits.dab import Dab
SYS = "SYS"
SUBUNIT = "DAB"
INITIALIZE_FULL_RESPONSES = [
(
(SUBUNIT, "AVAIL"),
[
(SUBUNIT, "AVAIL", "Ready"),
],
),
(
(SUBUNIT, "BAND"),
[
(SUBUNIT, "BAND", "FM"),
],
),
(
(SUBUNIT, "DABPRESET"),
[
(SUBUNIT, "DABPRESET", "33"),
],
),
(
(SUBUNIT, "FMFREQ"),
[
(SUBUNIT, "FMFREQ", "101.60"),
],
),
(
(SUBUNIT, "FMPRESET"),
[
(SUBUNIT, "FMPRESET", "40"),
],
),
(
(SUBUNIT, "FMRDSINFO"),
[
(SUBUNIT, "FMRDSPRGTYPE", "RDS PRG TYPE"),
(SUBUNIT, "FMRDSPRGSERVICE", "RDS PRG SERVICE"),
(SUBUNIT, "FMRDSTXT", "RDS RADIO TEXT"),
(SUBUNIT, "FMRDSCLOCK", "RDS CLOCK"),
(
SUBUNIT,
"DABDATETIME",
"13DEC'22 11:05",
), # DAB is a bit weird, but it came from a log OF RX-V500D
],
),
(
(SYS, "VERSION"),
[
(SYS, "VERSION", "Version"),
],
),
]
@pytest.fixture
def initialized_dab(connection) -> Dab:
connection.get_response_list = INITIALIZE_FULL_RESPONSES
dab = Dab(connection)
dab.initialize()
return dab
def test_initialize(connection, update_callback):
connection.get_response_list = INITIALIZE_FULL_RESPONSES
dab = Dab(connection)
dab.register_update_callback(update_callback)
dab.initialize()
assert dab.band is BandDab.FM
assert dab.fmfreq == 101.60
def test_band(connection, initialized_dab: Dab):
initialized_dab.band = BandDab.DAB
connection.put.assert_called_with(SUBUNIT, "BAND", "DAB")
connection.send_protocol_message(SUBUNIT, "BAND", "FM")
assert initialized_dab.band is BandDab.FM
initialized_dab.band = BandDab.FM
connection.put.assert_called_with(SUBUNIT, "BAND", "FM")
connection.send_protocol_message(SUBUNIT, "BAND", "DAB")
assert initialized_dab.band is BandDab.DAB
def test_dab(connection, initialized_dab: Dab):
connection.send_protocol_message(SUBUNIT, "DABCHLABEL", "dab ch label")
assert initialized_dab.dabchlabel == "dab ch label"
connection.send_protocol_message(SUBUNIT, "DABDLSLABEL", "dab dls label")
assert initialized_dab.dabdlslabel == "dab dls label"
connection.send_protocol_message(SUBUNIT, "DABENSEMBLELABEL", "dab ensemble label")
assert initialized_dab.dabensemblelabel == "dab ensemble label"
connection.send_protocol_message(SUBUNIT, "DABPRGTYPE", "dab prog type")
assert initialized_dab.dabprgtype == "dab prog type"
connection.send_protocol_message(SUBUNIT, "DABSERVICELABEL", "dab service label")
assert initialized_dab.dabservicelabel == "dab service label"
def test_fmrds(connection, initialized_dab: Dab):
# Updates from device
connection.send_protocol_message(SUBUNIT, "FMRDSPRGSERVICE", "rds prg service")
assert initialized_dab.fmrdsprgservice == "rds prg service"
connection.send_protocol_message(SUBUNIT, "FMRDSPRGTYPE", "rds prg type")
assert initialized_dab.fmrdsprgtype == "rds prg type"
connection.send_protocol_message(SUBUNIT, "FMRDSTXT", "radiotext")
assert initialized_dab.fmrdstxt == "radiotext"
def test_fmfreq(connection, initialized_dab: Dab):
# Set value and test stepsize handling (which is why it becomes 100.00)
initialized_dab.fmfreq = 100.05
connection.put.assert_called_with(SUBUNIT, "FMFREQ", "100.00")
def test_fmpreset(connection, initialized_dab: Dab):
assert initialized_dab.fmpreset == 40
initialized_dab.fmpreset = 12
connection.put.assert_called_with(SUBUNIT, "FMPRESET", "12")
connection.send_protocol_message(SUBUNIT, "FMPRESET", "No Preset")
initialized_dab.fmpreset = FmPreset.NO_PRESET
def test_dabpreset(connection, initialized_dab: Dab):
assert initialized_dab.dabpreset == 33
initialized_dab.dabpreset = 22
connection.put.assert_called_with(SUBUNIT, "DABPRESET", "22")
connection.send_protocol_message(SUBUNIT, "DABPRESET", "No Preset")
initialized_dab.dabpreset = DabPreset.NO_PRESET