2727 LOCATIONS ,
2828 LOGGER ,
2929 NONE ,
30- OBSOLETE_MEASUREMENTS ,
3130 OFF ,
3231 P1_MEASUREMENTS ,
3332 SENSORS ,
34- SPECIAL_PLUG_TYPES ,
3533 SPECIALS ,
3634 SWITCHES ,
3735 TEMP_CELSIUS ,
4139 ActuatorData ,
4240 ActuatorDataType ,
4341 ActuatorType ,
44- ApplianceType ,
4542 BinarySensorType ,
4643 DeviceData ,
4744 GatewayData ,
6158 check_model ,
6259 escape_illegal_xml_characters ,
6360 format_measure ,
64- power_data_local_format ,
61+ skip_obsolete_measurements ,
6562)
6663
6764# This way of importing aiohttp is because of patch/mocking in testing (aiohttp timeouts)
@@ -294,22 +291,7 @@ def _all_appliances(self) -> None:
294291 if appl .pwclass in THERMOSTAT_CLASSES and appl .location is None :
295292 continue
296293
297- self .gw_devices [appl .dev_id ] = {"dev_class" : appl .pwclass }
298- self ._count += 1
299- for key , value in {
300- "firmware" : appl .firmware ,
301- "hardware" : appl .hardware ,
302- "location" : appl .location ,
303- "mac_address" : appl .mac ,
304- "model" : appl .model ,
305- "name" : appl .name ,
306- "zigbee_mac_address" : appl .zigbee_mac ,
307- "vendor" : appl .vendor_name ,
308- }.items ():
309- if value is not None or key == "location" :
310- appl_key = cast (ApplianceType , key )
311- self .gw_devices [appl .dev_id ][appl_key ] = value
312- self ._count += 1
294+ self ._create_gw_devices (appl )
313295
314296 # For P1 collect the connected SmartMeter info
315297 if self .smile_type == "power" :
@@ -356,23 +338,7 @@ def _p1_smartmeter_info_finder(self, appl: Munch) -> None:
356338 location = self ._domain_objects .find (f'./location[@id="{ loc_id } "]' )
357339 appl = self ._energy_device_info_finder (appl , location )
358340
359- self .gw_devices [appl .dev_id ] = {"dev_class" : appl .pwclass }
360- self ._count += 1
361-
362- for key , value in {
363- "firmware" : appl .firmware ,
364- "hardware" : appl .hardware ,
365- "location" : appl .location ,
366- "mac_address" : appl .mac ,
367- "model" : appl .model ,
368- "name" : appl .name ,
369- "zigbee_mac_address" : appl .zigbee_mac ,
370- "vendor" : appl .vendor_name ,
371- }.items ():
372- if value is not None or key == "location" :
373- p1_key = cast (ApplianceType , key )
374- self .gw_devices [appl .dev_id ][p1_key ] = value
375- self ._count += 1
341+ self ._create_gw_devices (appl )
376342
377343 def _appliance_info_finder (self , appl : Munch , appliance : etree ) -> Munch :
378344 """Collect device info (Smile/Stretch, Thermostats, OpenTherm/On-Off): firmware, model and vendor name."""
@@ -591,68 +557,17 @@ def _power_data_from_location(self, loc_id: str) -> DeviceData:
591557 direct_data : DeviceData = {"sensors" : {}}
592558 loc = Munch ()
593559 log_list : list [str ] = ["point_log" , "cumulative_log" , "interval_log" ]
594- peak_list : list [str ] = ["nl_peak" , "nl_offpeak" ]
595560 t_string = "tariff"
596561
597562 search = self ._domain_objects
598563 loc .logs = search .find (f'./location[@id="{ loc_id } "]/logs' )
599564 for loc .measurement , loc .attrs in P1_MEASUREMENTS .items ():
600565 for loc .log_type in log_list :
601- for loc .peak_select in peak_list :
602- loc .locator = (
603- f'./{ loc .log_type } [type="{ loc .measurement } "]/period/'
604- f'measurement[@{ t_string } ="{ loc .peak_select } "]'
605- )
606- loc = self ._power_data_peak_value (loc )
607- if not loc .found :
608- continue
609-
610- direct_data = self ._power_data_energy_diff (
611- loc .measurement , loc .net_string , loc .f_val , direct_data
612- )
613- key = cast (SensorType , loc .key_string )
614- direct_data ["sensors" ][key ] = loc .f_val
566+ self ._collect_power_values (direct_data , loc , t_string )
615567
616568 self ._count += len (direct_data ["sensors" ])
617569 return direct_data
618570
619- def _power_data_peak_value (self , loc : Munch ) -> Munch :
620- """Helper-function for _power_data_from_location() and _power_data_from_modules()."""
621- loc .found = True
622- # If locator not found look for P1 gas_consumed or phase data (without tariff)
623- if loc .logs .find (loc .locator ) is None :
624- if "log" in loc .log_type and (
625- "gas" in loc .measurement or "phase" in loc .measurement
626- ):
627- # Avoid double processing by skipping one peak-list option
628- if loc .peak_select == "nl_offpeak" :
629- loc .found = False
630- return loc
631-
632- loc .locator = (
633- f'./{ loc .log_type } [type="{ loc .measurement } "]/period/measurement'
634- )
635- if loc .logs .find (loc .locator ) is None :
636- loc .found = False
637- return loc
638- else :
639- loc .found = False # pragma: no cover
640- return loc # pragma: no cover
641-
642- if (peak := loc .peak_select .split ("_" )[1 ]) == "offpeak" :
643- peak = "off_peak"
644- log_found = loc .log_type .split ("_" )[0 ]
645- loc .key_string = f"{ loc .measurement } _{ peak } _{ log_found } "
646- if "gas" in loc .measurement or loc .log_type == "point_meter" :
647- loc .key_string = f"{ loc .measurement } _{ log_found } "
648- if "phase" in loc .measurement :
649- loc .key_string = f"{ loc .measurement } "
650- loc .net_string = f"net_electricity_{ log_found } "
651- val = loc .logs .find (loc .locator ).text
652- loc .f_val = power_data_local_format (loc .attrs , loc .key_string , val )
653-
654- return loc
655-
656571 def _appliance_measurements (
657572 self ,
658573 appliance : etree ,
@@ -663,20 +578,8 @@ def _appliance_measurements(
663578 for measurement , attrs in measurements .items ():
664579 p_locator = f'.//logs/point_log[type="{ measurement } "]/period/measurement'
665580 if (appl_p_loc := appliance .find (p_locator )) is not None :
666- # Skip known obsolete measurements
667- updated_date_locator = (
668- f'.//logs/point_log[type="{ measurement } "]/updated_date'
669- )
670- if (
671- measurement in OBSOLETE_MEASUREMENTS
672- and (updated_date_key := appliance .find (updated_date_locator ))
673- is not None
674- ):
675- updated_date = updated_date_key .text .split ("T" )[0 ]
676- date_1 = dt .datetime .strptime (updated_date , "%Y-%m-%d" )
677- date_2 = dt .datetime .now ()
678- if int ((date_2 - date_1 ).days ) > 7 :
679- continue
581+ if skip_obsolete_measurements (appliance , measurement ):
582+ continue
680583
681584 if new_name := getattr (attrs , ATTR_NAME , None ):
682585 measurement = new_name
@@ -719,19 +622,6 @@ def _appliance_measurements(
719622 # Don't count the above top-level dicts, only the remaining single items
720623 self ._count += len (data ) - 3
721624
722- def _get_lock_state (self , xml : etree , data : DeviceData ) -> None :
723- """Helper-function for _get_measurement_data().
724-
725- Adam & Stretches: obtain the relay-switch lock state.
726- """
727- actuator = "actuator_functionalities"
728- func_type = "relay_functionality"
729- if xml .find ("type" ).text not in SPECIAL_PLUG_TYPES :
730- locator = f"./{ actuator } /{ func_type } /lock"
731- if (found := xml .find (locator )) is not None :
732- data ["switches" ]["lock" ] = found .text == "true"
733- self ._count += 1
734-
735625 def _get_toggle_state (
736626 self , xml : etree , toggle : str , name : ToggleNameType , data : DeviceData
737627 ) -> None :
0 commit comments