1- # type: ignore
2-
31"""Comprehensive tests for the OmniLogic API layer.
42
53Focuses on:
119
1210from __future__ import annotations
1311
14- from typing import TYPE_CHECKING
12+ from typing import TYPE_CHECKING , Any
1513from unittest .mock import AsyncMock , MagicMock , patch
1614from xml .etree import ElementTree as ET
1715
2018from pyomnilogic_local .api .api import OmniLogicAPI , _validate_id , _validate_speed , _validate_temperature
2119from pyomnilogic_local .api .constants import MAX_SPEED_PERCENT , MAX_TEMPERATURE_F , MIN_SPEED_PERCENT , MIN_TEMPERATURE_F , XML_NAMESPACE
2220from pyomnilogic_local .api .exceptions import OmniValidationError
23- from pyomnilogic_local .omnitypes import ColorLogicBrightness , ColorLogicShow40 , ColorLogicSpeed , HeaterMode
21+ from pyomnilogic_local .omnitypes import ColorLogicBrightness , ColorLogicShow40 , ColorLogicSpeed , HeaterMode , MessageType
2422
2523if TYPE_CHECKING :
2624 from pytest_subtests import SubTests
@@ -60,7 +58,7 @@ def _find_param(root: ET.Element, name: str) -> ET.Element:
6058
6159def test_validate_temperature (subtests : SubTests ) -> None :
6260 """Test temperature validation with various inputs using table-driven approach."""
63- test_cases = [
61+ test_cases : list [ tuple [ Any , str , bool , str ]] = [
6462 # (temperature, param_name, should_pass, description) # noqa: ERA001
6563 (MIN_TEMPERATURE_F , "temp" , True , "minimum valid temperature" ),
6664 (MAX_TEMPERATURE_F , "temp" , True , "maximum valid temperature" ),
@@ -83,7 +81,7 @@ def test_validate_temperature(subtests: SubTests) -> None:
8381
8482def test_validate_speed (subtests : SubTests ) -> None :
8583 """Test speed validation with various inputs using table-driven approach."""
86- test_cases = [
84+ test_cases : list [ tuple [ Any , str , bool , str ]] = [
8785 # (speed, param_name, should_pass, description) # noqa: ERA001
8886 (MIN_SPEED_PERCENT , "speed" , True , "minimum valid speed (0)" ),
8987 (MAX_SPEED_PERCENT , "speed" , True , "maximum valid speed (100)" ),
@@ -106,7 +104,7 @@ def test_validate_speed(subtests: SubTests) -> None:
106104
107105def test_validate_id (subtests : SubTests ) -> None :
108106 """Test ID validation with various inputs using table-driven approach."""
109- test_cases = [
107+ test_cases : list [ tuple [ Any , str , bool , str ]] = [
110108 # (id_value, param_name, should_pass, description) # noqa: ERA001
111109 (0 , "pool_id" , True , "zero ID" ),
112110 (1 , "pool_id" , True , "positive ID" ),
@@ -149,7 +147,7 @@ def test_api_init_custom_params() -> None:
149147
150148def test_api_init_validation (subtests : SubTests ) -> None :
151149 """Test OmniLogicAPI initialization validation using table-driven approach."""
152- test_cases = [
150+ test_cases : list [ tuple [ Any , Any , Any , bool , str ]] = [
153151 # (ip, port, timeout, should_pass, description) # noqa: ERA001
154152 ("" , 10444 , 5.0 , False , "empty IP address" ),
155153 ("192.168.1.100" , 0 , 5.0 , False , "zero port" ),
@@ -489,7 +487,7 @@ async def test_async_send_message_creates_transport() -> None:
489487 with patch ("asyncio.get_running_loop" ) as mock_loop :
490488 mock_loop .return_value .create_datagram_endpoint = AsyncMock (return_value = (mock_transport , mock_protocol ))
491489
492- await api .async_send_message (0x01 , "test" , need_response = False )
490+ await api .async_send_message (MessageType . REQUEST_CONFIGURATION , "test" , need_response = False )
493491
494492 # Verify endpoint was created with correct parameters
495493 mock_loop .return_value .create_datagram_endpoint .assert_called_once ()
@@ -512,7 +510,7 @@ async def test_async_send_message_with_response() -> None:
512510 with patch ("asyncio.get_running_loop" ) as mock_loop :
513511 mock_loop .return_value .create_datagram_endpoint = AsyncMock (return_value = (mock_transport , mock_protocol ))
514512
515- result = await api .async_send_message (0x01 , "test" , need_response = True )
513+ result = await api .async_send_message (MessageType . REQUEST_CONFIGURATION , "test" , need_response = True )
516514
517515 assert result == "test response"
518516 mock_protocol .send_and_receive .assert_called_once ()
@@ -531,7 +529,7 @@ async def test_async_send_message_without_response() -> None:
531529 with patch ("asyncio.get_running_loop" ) as mock_loop :
532530 mock_loop .return_value .create_datagram_endpoint = AsyncMock (return_value = (mock_transport , mock_protocol ))
533531
534- result = await api .async_send_message (0x01 , "test" , need_response = False )
532+ result = await api .async_send_message (MessageType . REQUEST_CONFIGURATION , "test" , need_response = False ) # type: ignore[func-returns-value]
535533
536534 assert result is None
537535 mock_protocol .send_message .assert_called_once ()
@@ -551,7 +549,7 @@ async def test_async_send_message_closes_transport_on_error() -> None:
551549 mock_loop .return_value .create_datagram_endpoint = AsyncMock (return_value = (mock_transport , mock_protocol ))
552550
553551 with pytest .raises (Exception , match = "Test error" ):
554- await api .async_send_message (0x01 , "test" , need_response = False )
552+ await api .async_send_message (MessageType . REQUEST_CONFIGURATION , "test" , need_response = False )
555553
556554 # Verify transport was still closed despite the error
557555 mock_transport .close .assert_called_once ()
0 commit comments