@@ -200,47 +200,92 @@ def test_none_states(self):
200200 device = Device (** hump_device )
201201 assert not device .states .get (STATE )
202202
203- def test_get_supported_command_name (self ):
204- """Device.get_supported_command_name () delegates to commands.select() ."""
203+ def test_select_first_command (self ):
204+ """Device.select_first_command () returns first supported command from list ."""
205205 hump_device = humps .decamelize (RAW_DEVICES )
206206 device = Device (** hump_device )
207- assert (
208- device .get_supported_command_name (["nonexistent" , "open" , "close" ])
209- == "open"
210- )
211- assert device .get_supported_command_name (["nonexistent" ]) is None
207+ assert device .select_first_command (["nonexistent" , "open" , "close" ]) == "open"
208+ assert device .select_first_command (["nonexistent" ]) is None
209+
210+ def test_supports_command (self ):
211+ """Device.supports_command() checks if device supports a single command."""
212+ hump_device = humps .decamelize (RAW_DEVICES )
213+ device = Device (** hump_device )
214+ assert device .supports_command ("open" )
215+ assert not device .supports_command ("nonexistent" )
212216
213- def test_has_supported_command (self ):
214- """Device.has_supported_command () delegates to commands.has_any() ."""
217+ def test_supports_any_command (self ):
218+ """Device.supports_any_command () checks if device supports any command ."""
215219 hump_device = humps .decamelize (RAW_DEVICES )
216220 device = Device (** hump_device )
217- assert device .has_supported_command (["nonexistent" , "open" ])
218- assert not device .has_supported_command (["nonexistent" ])
221+ assert device .supports_any_command (["nonexistent" , "open" ])
222+ assert not device .supports_any_command (["nonexistent" ])
219223
220224 def test_get_state_value (self ):
221- """Device.get_state_value() returns the value of the first matching state."""
225+ """Device.get_state_value() returns value of a single state."""
226+ hump_device = humps .decamelize (RAW_DEVICES )
227+ device = Device (** hump_device )
228+ value = device .get_state_value ("core:ClosureState" )
229+ assert value == 100
230+ assert device .get_state_value ("nonexistent" ) is None
231+
232+ def test_select_first_state_value (self ):
233+ """Device.select_first_state_value() returns value of first matching state from list."""
222234 hump_device = humps .decamelize (RAW_DEVICES )
223235 device = Device (** hump_device )
224- value = device .get_state_value (["nonexistent" , "core:ClosureState" ])
236+ value = device .select_first_state_value (["nonexistent" , "core:ClosureState" ])
225237 assert value == 100
226238
227239 def test_has_state_value (self ):
228- """Device.has_state_value() returns True if any state exists with non-None value."""
240+ """Device.has_state_value() checks if a single state exists with non-None value."""
241+ hump_device = humps .decamelize (RAW_DEVICES )
242+ device = Device (** hump_device )
243+ assert device .has_state_value ("core:ClosureState" )
244+ assert not device .has_state_value ("nonexistent" )
245+
246+ def test_has_any_state_value (self ):
247+ """Device.has_any_state_value() checks if any state exists with non-None value."""
229248 hump_device = humps .decamelize (RAW_DEVICES )
230249 device = Device (** hump_device )
231- assert device .has_state_value (["nonexistent" , "core:ClosureState" ])
232- assert not device .has_state_value (["nonexistent" ])
250+ assert device .has_any_state_value (["nonexistent" , "core:ClosureState" ])
251+ assert not device .has_any_state_value (["nonexistent" ])
233252
234253 def test_get_state_definition (self ):
235- """Device.get_state_definition() returns the first matching StateDefinition."""
254+ """Device.get_state_definition() returns StateDefinition for a single state."""
255+ hump_device = humps .decamelize (RAW_DEVICES )
256+ device = Device (** hump_device )
257+ state_def = device .get_state_definition ("core:ClosureState" )
258+ assert state_def is not None
259+ assert state_def .qualified_name == "core:ClosureState"
260+ assert device .get_state_definition ("nonexistent" ) is None
261+
262+ def test_select_first_state_definition (self ):
263+ """Device.select_first_state_definition() returns first matching StateDefinition from list."""
236264 hump_device = humps .decamelize (RAW_DEVICES )
237265 device = Device (** hump_device )
238- state_def = device .get_state_definition (["nonexistent" , "core:ClosureState" ])
266+ state_def = device .select_first_state_definition (
267+ ["nonexistent" , "core:ClosureState" ]
268+ )
239269 assert state_def is not None
240270 assert state_def .qualified_name == "core:ClosureState"
241271
242- def test_get_attribute_value_returns_first_match (self ):
243- """Device.get_attribute_value() returns the value of the first matching attribute."""
272+ def test_get_attribute_value (self ):
273+ """Device.get_attribute_value() returns value of a single attribute."""
274+ test_device = {
275+ ** RAW_DEVICES ,
276+ "attributes" : [
277+ {"name" : "core:Manufacturer" , "type" : 3 , "value" : "VELUX" },
278+ {"name" : "core:Model" , "type" : 3 , "value" : "WINDOW 100" },
279+ ],
280+ }
281+ hump_device = humps .decamelize (test_device )
282+ device = Device (** hump_device )
283+ value = device .get_attribute_value ("core:Model" )
284+ assert value == "WINDOW 100"
285+ assert device .get_attribute_value ("nonexistent" ) is None
286+
287+ def test_select_first_attribute_value_returns_first_match (self ):
288+ """Device.select_first_attribute_value() returns value of first matching attribute from list."""
244289 test_device = {
245290 ** RAW_DEVICES ,
246291 "attributes" : [
@@ -250,28 +295,28 @@ def test_get_attribute_value_returns_first_match(self):
250295 }
251296 hump_device = humps .decamelize (test_device )
252297 device = Device (** hump_device )
253- value = device .get_attribute_value (
298+ value = device .select_first_attribute_value (
254299 ["nonexistent" , "core:Model" , "core:Manufacturer" ]
255300 )
256301 assert value == "WINDOW 100"
257302
258- def test_get_attribute_value_returns_none_when_no_match (self ):
259- """Device.get_attribute_value () returns None when no attribute matches."""
303+ def test_select_first_attribute_value_returns_none_when_no_match (self ):
304+ """Device.select_first_attribute_value () returns None when no attribute matches."""
260305 hump_device = humps .decamelize (RAW_DEVICES )
261306 device = Device (** hump_device )
262- value = device .get_attribute_value (["nonexistent" , "also_nonexistent" ])
307+ value = device .select_first_attribute_value (["nonexistent" , "also_nonexistent" ])
263308 assert value is None
264309
265- def test_get_attribute_value_empty_attributes (self ):
266- """Device.get_attribute_value () returns None for devices with no attributes."""
310+ def test_select_first_attribute_value_empty_attributes (self ):
311+ """Device.select_first_attribute_value () returns None for devices with no attributes."""
267312 test_device = {** RAW_DEVICES , "attributes" : []}
268313 hump_device = humps .decamelize (test_device )
269314 device = Device (** hump_device )
270- value = device .get_attribute_value (["core:Manufacturer" ])
315+ value = device .select_first_attribute_value (["core:Manufacturer" ])
271316 assert value is None
272317
273- def test_get_attribute_value_with_none_values (self ):
274- """Device.get_attribute_value () skips attributes with None values."""
318+ def test_select_first_attribute_value_with_none_values (self ):
319+ """Device.select_first_attribute_value () skips attributes with None values."""
275320 test_device = {
276321 ** RAW_DEVICES ,
277322 "attributes" : [
@@ -281,7 +326,7 @@ def test_get_attribute_value_with_none_values(self):
281326 }
282327 hump_device = humps .decamelize (test_device )
283328 device = Device (** hump_device )
284- value = device .get_attribute_value (["core:Model" , "core:Manufacturer" ])
329+ value = device .select_first_attribute_value (["core:Model" , "core:Manufacturer" ])
285330 assert value == "VELUX"
286331
287332
0 commit comments