@@ -31,6 +31,43 @@ def reading_json_fixture():
3131 }
3232
3333
34+ @pytest .fixture (name = "reading_alt_obis_json" )
35+ def reading_alt_obis_json_fixture ():
36+ """Fixture reading response with alternate current power OBIS only."""
37+ return {
38+ "__typename" : "iometer.reading.v1" ,
39+ "meter" : {
40+ "number" : "1ISK0000000000" ,
41+ "reading" : {
42+ "time" : "2024-11-11T11:11:11Z" ,
43+ "registers" : [
44+ {"obis" : "01-00:01.08.00*ff" , "value" : 1111.1 , "unit" : "Wh" },
45+ {"obis" : "01-00:02.08.00*ff" , "value" : 2222.2 , "unit" : "Wh" },
46+ {"obis" : "01-00:24.07.00*ff" , "value" : 200 , "unit" : "W" },
47+ ],
48+ },
49+ },
50+ }
51+
52+
53+ @pytest .fixture (name = "reading_no_power_obis_json" )
54+ def reading_no_power_obis_json_fixture ():
55+ """Fixture reading response without any current power OBIS registers."""
56+ return {
57+ "__typename" : "iometer.reading.v1" ,
58+ "meter" : {
59+ "number" : "1ISK0000000000" ,
60+ "reading" : {
61+ "time" : "2024-11-11T11:11:11Z" ,
62+ "registers" : [
63+ {"obis" : "01-00:01.08.00*ff" , "value" : 3333.3 , "unit" : "Wh" },
64+ {"obis" : "01-00:02.08.00*ff" , "value" : 4444.4 , "unit" : "Wh" },
65+ ],
66+ },
67+ },
68+ }
69+
70+
3471@pytest .fixture (name = "status_json" )
3572def status_json_fixture ():
3673 """ "Fixture status response"""
@@ -184,6 +221,32 @@ async def test_get_current_reading(client_iometer, mock_aioresponse, reading_jso
184221 assert reading .get_current_power () == 100
185222
186223
224+ @pytest .mark .asyncio
225+ async def test_get_current_reading_alt_obis (
226+ client_iometer , mock_aioresponse , reading_alt_obis_json
227+ ):
228+ """Test current power using alternate OBIS when primary is missing."""
229+ mock_endpoint = f"http://{ HOST } /v1/reading"
230+ mock_aioresponse .get (mock_endpoint , status = 200 , payload = reading_alt_obis_json )
231+
232+ reading = await client_iometer .get_current_reading ()
233+ assert isinstance (reading , Reading )
234+ assert reading .get_current_power () == 200
235+
236+
237+ @pytest .mark .asyncio
238+ async def test_get_current_reading_no_power_obis (
239+ client_iometer , mock_aioresponse , reading_no_power_obis_json
240+ ):
241+ """Test current power returns None when no power OBIS registers are present."""
242+ mock_endpoint = f"http://{ HOST } /v1/reading"
243+ mock_aioresponse .get (mock_endpoint , status = 200 , payload = reading_no_power_obis_json )
244+
245+ reading = await client_iometer .get_current_reading ()
246+ assert isinstance (reading , Reading )
247+ assert reading .get_current_power () is None
248+
249+
187250@pytest .mark .asyncio
188251async def test_get_current_status (client_iometer , mock_aioresponse , status_json ):
189252 """Test getting device status."""
0 commit comments