2121from .coordinator import SigenergyDataUpdateCoordinator
2222from .sigen_entity import SigenergyEntity
2323from .common import generate_sigen_entity
24+ from .calculated_sensor import SigenergyCalculations
2425
2526_LOGGER = logging .getLogger (__name__ )
2627
@@ -42,9 +43,16 @@ class SigenergyBinarySensorEntityDescription(
4243 name = "PV Generating" ,
4344 device_class = BinarySensorDeviceClass .POWER ,
4445 icon = "mdi:solar-power" ,
45- source_key = "plant_photovoltaic_power" ,
46- value_fn = lambda data : (val := data .get ("plant_photovoltaic_power" )) \
47- is not None and Decimal (str (val )) > Decimal ("0.01" ),
46+ source_key = None , # No longer a direct key, calculated from multiple values
47+ value_fn = lambda data : (
48+ (
49+ power := SigenergyCalculations .calculate_total_pv_power (
50+ None , coordinator_data = {"plant" : data }
51+ )
52+ )
53+ is not None
54+ and power > 0.01
55+ ),
4856 ),
4957 SigenergyBinarySensorEntityDescription (
5058 key = "plant_battery_charging" ,
@@ -161,11 +169,17 @@ def is_on(self) -> bool | None:
161169
162170 plant_data = self .coordinator .data ["plant" ]
163171
164- # Check if the source key exists in the plant data
165- if self .entity_description .source_key not in plant_data :
166- _LOGGER .debug ("[%s] Source key '%s' not found in plant data" ,
167- self .entity_id , self .entity_description .source_key )
168- return None # Source data missing
172+ # If a source key is defined, check if it exists in the plant data
173+ if (
174+ self .entity_description .source_key is not None
175+ and self .entity_description .source_key not in plant_data
176+ ):
177+ _LOGGER .debug (
178+ "[%s] Source key '%s' not found in plant data" ,
179+ self .entity_id ,
180+ self .entity_description .source_key ,
181+ )
182+ return None # Source data missing
169183
170184 # Check if value_fn is defined
171185 if self .entity_description .value_fn is None :
0 commit comments