@@ -187,26 +187,33 @@ async def _smile_detect(
187187 """Helper-function for connect().
188188
189189 Detect which type of Plugwise Gateway is being connected.
190+ Store the collected data, also collect some specific thermostat devices.
190191 """
192+ model = await self ._collect_smile_data (dsmrmain , result )
193+ self ._store_smile_data (model )
194+ self ._process_for_thermostat (result )
195+
196+ async def _collect_smile_data (
197+ self , dsmrmain : etree .Element , result : etree .Element
198+ ) -> str :
199+ """Collect smile/gateway data."""
191200 model : str = "Unknown"
192201 if (gateway := result .find ("./gateway" )) is not None :
193202 self .smile .version = parse (gateway .find ("firmware_version" ).text )
194203 self .smile .hw_version = gateway .find ("hardware_version" ).text
195204 self .smile .hostname = gateway .find ("hostname" ).text
196205 self .smile .mac_address = gateway .find ("mac_address" ).text
197- if (vendor_model := gateway .find ("vendor_model" )) is None :
198- return # pragma: no cover
206+ if (vendor_model := gateway .find ("vendor_model" )) is not None :
207+ model = vendor_model . text
199208
200- model = vendor_model . text
201- elec_measurement = gateway . find (
202- "gateway_environment/electricity_consumption_tariff_structure "
209+ # Check for Anna P1 function
210+ elec_point_meters = result . findall (
211+ "./location/logs/point_log/electricity_point_meter "
203212 )
204- if (
205- elec_measurement is not None
206- and elec_measurement .text
207- and model == "smile_thermo"
208- ):
209- self .smile .anna_p1 = True
213+ for meter in elec_point_meters :
214+ if meter .get ("id" ) and model == "smile_thermo" :
215+ self .smile .anna_p1 = True
216+ break
210217 else :
211218 model = await self ._smile_detect_legacy (result , dsmrmain , model )
212219
@@ -220,6 +227,35 @@ async def _smile_detect(
220227 )
221228 raise UnsupportedDeviceError
222229
230+ return model
231+
232+ def _process_for_thermostat (self , result : etree .Element ) -> None :
233+ """Extra processing for thermostats."""
234+ if self .smile .type != "thermostat" :
235+ return
236+
237+ self ._is_thermostat = True
238+ # For Adam, Anna, determine the system capabilities:
239+ # Find the connected heating/cooling device (heater_central),
240+ # e.g. heat-pump or gas-fired heater
241+ onoff_boiler = result .find ("./module/protocols/onoff_boiler" )
242+ open_therm_boiler = result .find ("./module/protocols/open_therm_boiler" )
243+ self ._on_off_device = onoff_boiler is not None
244+ self ._opentherm_device = open_therm_boiler is not None
245+
246+ # Determine the presence of special features
247+ locator_1 = "./gateway/features/cooling"
248+ locator_2 = "./gateway/features/elga_support"
249+ if result .find (locator_1 ) is not None :
250+ self ._cooling_present = True
251+ if result .find (locator_2 ) is not None :
252+ self ._elga = True
253+
254+ def _store_smile_data (self , model : str ) -> None :
255+ """Store the collected the smile/gateway data.
256+
257+ Perform some checks, and set a shorter timeout for non-legacy Gateways.
258+ """
223259 version_major = str (self .smile .version .major )
224260 self ._target_smile = f"{ model } _v{ version_major } "
225261 LOGGER .debug ("Plugwise identified as %s" , self ._target_smile )
@@ -251,30 +287,6 @@ async def _smile_detect(
251287 if self .smile .type == "stretch" :
252288 self ._stretch_v2 = int (version_major ) == 2
253289
254- self ._process_for_thermostat (result )
255-
256- def _process_for_thermostat (self , result : etree .Element ) -> None :
257- """Extra processing for thermostats."""
258- if self .smile .type != "thermostat" :
259- return
260-
261- self ._is_thermostat = True
262- # For Adam, Anna, determine the system capabilities:
263- # Find the connected heating/cooling device (heater_central),
264- # e.g. heat-pump or gas-fired heater
265- onoff_boiler = result .find ("./module/protocols/onoff_boiler" )
266- open_therm_boiler = result .find ("./module/protocols/open_therm_boiler" )
267- self ._on_off_device = onoff_boiler is not None
268- self ._opentherm_device = open_therm_boiler is not None
269-
270- # Determine the presence of special features
271- locator_1 = "./gateway/features/cooling"
272- locator_2 = "./gateway/features/elga_support"
273- if result .find (locator_1 ) is not None :
274- self ._cooling_present = True
275- if result .find (locator_2 ) is not None :
276- self ._elga = True
277-
278290 async def _smile_detect_legacy (
279291 self , result : etree .Element , dsmrmain : etree .Element , model : str
280292 ) -> str :
0 commit comments