@@ -41,9 +41,9 @@ def reading_alt_obis_json_fixture():
4141 "reading" : {
4242 "time" : "2024-11-11T11:11:11Z" ,
4343 "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" },
44+ {"obis" : "01-00:01.08.00*ff" , "value" : 1234.5 , "unit" : "Wh" },
45+ {"obis" : "01-00:02.08.00*ff" , "value" : 5432.1 , "unit" : "Wh" },
46+ {"obis" : "01-00:24.07.00*ff" , "value" : 100 , "unit" : "W" },
4747 ],
4848 },
4949 },
@@ -60,8 +60,27 @@ def reading_no_power_obis_json_fixture():
6060 "reading" : {
6161 "time" : "2024-11-11T11:11:11Z" ,
6262 "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" },
63+ {"obis" : "01-00:01.08.00*ff" , "value" : 1234.5 , "unit" : "Wh" },
64+ {"obis" : "01-00:02.08.00*ff" , "value" : 5432.1 , "unit" : "Wh" },
65+ ],
66+ },
67+ },
68+ }
69+
70+
71+ @pytest .fixture (name = "reading_no_power_no_production_obis_json" )
72+ def reading_no_power_no_production_obis_json_fixture ():
73+ """Fixture reading response without any current power OBIS
74+ and production OBIS register.
75+ """
76+ return {
77+ "__typename" : "iometer.reading.v1" ,
78+ "meter" : {
79+ "number" : "1ISK0000000000" ,
80+ "reading" : {
81+ "time" : "2024-11-11T11:11:11Z" ,
82+ "registers" : [
83+ {"obis" : "01-00:01.08.00*ff" , "value" : 1234.5 , "unit" : "Wh" }
6584 ],
6685 },
6786 },
@@ -231,7 +250,7 @@ async def test_get_current_reading_alt_obis(
231250
232251 reading = await client_iometer .get_current_reading ()
233252 assert isinstance (reading , Reading )
234- assert reading .get_current_power () == 200
253+ assert reading .get_current_power () == 100
235254
236255
237256@pytest .mark .asyncio
@@ -245,6 +264,25 @@ async def test_get_current_reading_no_power_obis(
245264 reading = await client_iometer .get_current_reading ()
246265 assert isinstance (reading , Reading )
247266 assert reading .get_current_power () is None
267+ assert reading .get_total_production () == 5432.1
268+ assert reading .get_total_consumption () == 1234.5
269+
270+
271+ @pytest .mark .asyncio
272+ async def test_get_current_reading_no_power_no_production_obis (
273+ client_iometer , mock_aioresponse , reading_no_power_no_production_obis_json
274+ ):
275+ """Test current power returns None when no power OBIS registers are present."""
276+ mock_endpoint = f"http://{ HOST } /v1/reading"
277+ mock_aioresponse .get (
278+ mock_endpoint , status = 200 , payload = reading_no_power_no_production_obis_json
279+ )
280+
281+ reading = await client_iometer .get_current_reading ()
282+ assert isinstance (reading , Reading )
283+ assert reading .get_current_power () is None
284+ assert reading .get_total_production () is None
285+ assert reading .get_total_consumption () == 1234.5
248286
249287
250288@pytest .mark .asyncio
0 commit comments