@@ -7681,6 +7681,48 @@ def test_fox_build_discovery_sets_inverter_type_only_where_automatic_config_woul
76817681 return 0
76827682
76837683
7684+ def test_fox_build_discovery_survives_a_capacity_that_is_not_a_number (my_predbat ):
7685+ """A capacity that is not a positive number drops the rating, not the whole report.
7686+
7687+ capacity_watts() multiplies the raw field by 1000.0, so a non-empty string would raise inside
7688+ build_discovery(); refresh_discovery() would catch that and file nothing for any Fox device.
7689+ The rating is read under the same test drives_it applies: a positive int or float.
7690+ """
7691+ print ("**** test_fox_build_discovery_survives_a_capacity_that_is_not_a_number ****" )
7692+ for capacity in ("8" , "unknown" , - 8 , None ):
7693+ fox = _fox_discovery_api (my_predbat )
7694+ fox .device_detail ["BATT001" ]["capacity" ] = capacity
7695+
7696+ report = fox .build_discovery ()
7697+
7698+ by_id = {record ["device_id" ]: record for record in report ["inverters" ]}
7699+ assert set (by_id ) == {"fox:BATT001" , "fox:PVONLY1" }, f"capacity { capacity !r} : every device is still reported"
7700+ battery = by_id ["fox:BATT001" ]
7701+ assert "inverter_w" not in battery .get ("ratings" , {}), f"capacity { capacity !r} is not a rating: { battery .get ('ratings' )} "
7702+ assert "inverter_type" not in battery , f"capacity { capacity !r} : automatic_config() would not drive this device"
7703+ assert sorted (battery ["functions" ]) == ["battery" , "solar" ], "the rest of the record is unaffected"
7704+ assert by_id ["fox:PVONLY1" ]["ratings" ]["inverter_w" ] == 5000.0 , "the other device keeps its rating"
7705+ print ("PASS: Fox reports every device when a capacity is not a number" )
7706+ return 0
7707+
7708+
7709+ def test_fox_build_discovery_matches_export_limit_as_automatic_config_does (my_predbat ):
7710+ """export_limit is found by the same case-insensitive match automatic_config() uses for hasExportLimit."""
7711+ print ("**** test_fox_build_discovery_matches_export_limit_as_automatic_config_does ****" )
7712+ for name in ("ExportLimit" , "exportlimit" , "EXPORTLIMIT" ):
7713+ fox = _fox_discovery_api (my_predbat )
7714+ fox .device_settings ["BATT001" ] = {name : {"value" : 12000.0 }}
7715+ battery = {record ["device_id" ]: record for record in fox .build_discovery ()["inverters" ]}["fox:BATT001" ]
7716+ assert "export_limit" in battery ["capabilities" ], f"setting { name !r} : { battery ['capabilities' ]} "
7717+
7718+ fox = _fox_discovery_api (my_predbat )
7719+ fox .device_settings ["BATT001" ] = {"WorkMode" : {"value" : "SelfUse" }}
7720+ battery = {record ["device_id" ]: record for record in fox .build_discovery ()["inverters" ]}["fox:BATT001" ]
7721+ assert "export_limit" not in battery ["capabilities" ], "no ExportLimit setting, no capability"
7722+ print ("PASS: Fox matches ExportLimit as automatic_config() does" )
7723+ return 0
7724+
7725+
76847726def test_fox_build_discovery_returns_none_before_discovery (my_predbat ):
76857727 """With no devices found yet there is nothing to describe, so nothing is reported."""
76867728 print ("**** test_fox_build_discovery_returns_none_before_discovery ****" )
@@ -8043,6 +8085,8 @@ def run_fox_api_tests(my_predbat):
80438085 failed |= test_fox_build_discovery_round_trips_through_validate_report (my_predbat )
80448086 failed |= test_fox_build_discovery_battery_ratings_tell_the_aio_bug_from_a_healthy_stack (my_predbat )
80458087 failed |= test_fox_build_discovery_sets_inverter_type_only_where_automatic_config_would (my_predbat )
8088+ failed |= test_fox_build_discovery_survives_a_capacity_that_is_not_a_number (my_predbat )
8089+ failed |= test_fox_build_discovery_matches_export_limit_as_automatic_config_does (my_predbat )
80468090 failed |= test_fox_build_discovery_returns_none_before_discovery (my_predbat )
80478091 failed |= test_fox_run_reports_discovery_and_survives_a_failure (my_predbat )
80488092 failed |= test_fox_run_reports_discovery_when_automatic_config_fails (my_predbat )
0 commit comments