Skip to content

Commit 8b77b4e

Browse files
committed
Improve logging on device creation
1 parent fe53830 commit 8b77b4e

1 file changed

Lines changed: 28 additions & 21 deletions

File tree

domoticz/plugin.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ def onStart(self):
121121
for unit in Devices:
122122
try:
123123
device = Devices[unit]
124+
Domoticz.Debug(f"Found existing device: Unit {unit}, Name: {device.Name}, DeviceID: {device.DeviceID}")
125+
124126
# Check if unit number is valid
125-
if unit > 255:
127+
if isinstance(unit, int) and unit > 255:
126128
Domoticz.Log(f"Found device with invalid unit {unit}: {device.Name} - marking for deletion")
127129
devices_to_delete.append(unit)
128130
# Try to access device properties to detect corruption
@@ -688,7 +690,7 @@ def updateZoneDevice(self, zone_id: int, zone_name: str, state: Dict[str, Any]):
688690
This provides a clean hierarchy supporting unlimited zones.
689691
All zone devices report battery status from the zone's leader thermostat.
690692
"""
691-
Domoticz.Debug(f"updateZoneDevice: {zone_name}")
693+
Domoticz.Log(f"updateZoneDevice called: zone_id={zone_id}, zone_name='{zone_name}'")
692694

693695
# Safety check - don't create/update devices if we don't have valid state
694696
if not state:
@@ -721,27 +723,28 @@ def updateZoneDevice(self, zone_id: int, zone_name: str, state: Dict[str, Any]):
721723

722724
# Create temperature + humidity device if needed (Unit X, Sub-unit 1)
723725
device_key = (unit, temp_subunit)
724-
if device_key not in Devices and device_key not in self.device_creation_attempted:
725-
Domoticz.Log(f"Creating temperature sensor for zone: {zone_name} (Unit {unit}, Sub-unit {temp_subunit})")
726+
if device_key not in self.device_creation_attempted:
726727
self.device_creation_attempted.add(device_key)
727728

728729
try:
730+
# Try to create - will fail silently if already exists
729731
Domoticz.Device(
730732
Name=f"{zone_name}",
731733
Unit=unit,
732734
DeviceID=f"{unit}:{temp_subunit}", # Extended Framework ID with sub-unit
733735
TypeName="Temp+Hum",
734736
Used=1 if self.auto_enable_devices else 0
735737
).Create()
736-
Domoticz.Debug(f"Successfully created temp sensor for {zone_name}")
738+
Domoticz.Log(f"Created temperature sensor for zone: {zone_name} (Unit {unit}, Sub-unit {temp_subunit})")
737739
except Exception as e:
738-
# Device might already exist - this is not fatal
739-
Domoticz.Debug(f"Device ({unit}:{temp_subunit}) already exists or creation failed: {e}")
740+
# Device already exists - this is normal and not an error
741+
Domoticz.Debug(f"Temp sensor ({unit}:{temp_subunit}) for {zone_name} already exists")
742+
else:
743+
Domoticz.Debug(f"Skipping temp sensor for {zone_name} - already attempted in this session")
740744

741745
# Create thermostat setpoint device if needed (Unit X, Sub-unit 2)
742746
device_key = (unit, setpoint_subunit)
743-
if device_key not in Devices and device_key not in self.device_creation_attempted:
744-
Domoticz.Log(f"Creating thermostat for zone: {zone_name} (Unit {unit}, Sub-unit {setpoint_subunit})")
747+
if device_key not in self.device_creation_attempted:
745748
self.device_creation_attempted.add(device_key)
746749

747750
try:
@@ -755,14 +758,15 @@ def updateZoneDevice(self, zone_id: int, zone_name: str, state: Dict[str, Any]):
755758
Used=1 if self.auto_enable_devices else 0
756759
).Create()
757760

758-
Domoticz.Log(f"Created thermostat setpoint for {zone_name} - Unit {unit}, Sub-unit {setpoint_subunit}")
761+
Domoticz.Log(f"Created thermostat for zone: {zone_name} (Unit {unit}, Sub-unit {setpoint_subunit})")
759762
except Exception as e:
760-
Domoticz.Debug(f"Device ({unit}:{setpoint_subunit}) already exists or creation failed: {e}")
763+
Domoticz.Debug(f"Thermostat ({unit}:{setpoint_subunit}) for {zone_name} already exists")
764+
else:
765+
Domoticz.Debug(f"Skipping thermostat for {zone_name} - already attempted")
761766

762767
# Create heating status indicator (Unit X, Sub-unit 3)
763768
device_key = (unit, heating_subunit)
764-
if device_key not in Devices and device_key not in self.device_creation_attempted:
765-
Domoticz.Log(f"Creating heating status for zone: {zone_name} (Unit {unit}, Sub-unit {heating_subunit})")
769+
if device_key not in self.device_creation_attempted:
766770
self.device_creation_attempted.add(device_key)
767771

768772
try:
@@ -775,9 +779,11 @@ def updateZoneDevice(self, zone_id: int, zone_name: str, state: Dict[str, Any]):
775779
Used=1 if self.auto_enable_devices else 0
776780
).Create()
777781

778-
Domoticz.Log(f"Created heating indicator for {zone_name} - Unit {unit}, Sub-unit {heating_subunit}")
782+
Domoticz.Log(f"Created heating indicator for zone: {zone_name} (Unit {unit}, Sub-unit {heating_subunit})")
779783
except Exception as e:
780-
Domoticz.Debug(f"Device ({unit}:{heating_subunit}) already exists or creation failed: {e}")
784+
Domoticz.Debug(f"Heating indicator ({unit}:{heating_subunit}) for {zone_name} already exists")
785+
else:
786+
Domoticz.Debug(f"Skipping heating indicator for {zone_name} - already attempted")
781787

782788
# Extract state values
783789
cur_temp = state.get('cur_temp_c')
@@ -887,23 +893,24 @@ def updateThermostatDevice(self, device_id: int, zone_id: int, zone_name: str, s
887893

888894
# Create temperature + humidity device if needed
889895
device_key = (unit, subunit)
890-
if device_key not in Devices and device_key not in self.device_creation_attempted:
891-
# Create device with zone + serial name for identification
892-
device_name = f"{zone_name} ({serial_number[-4:]})"
893-
Domoticz.Log(f"Creating thermostat sensor: {device_name} (Unit {unit}, Sub-unit {subunit})")
896+
if device_key not in self.device_creation_attempted:
894897
self.device_creation_attempted.add(device_key)
895898

896899
try:
900+
# Create device with zone + serial name for identification
901+
device_name = f"{zone_name} ({serial_number[-4:]})"
897902
Domoticz.Device(
898903
Name=device_name,
899904
Unit=unit,
900905
DeviceID=f"{unit}:{subunit}", # Extended Framework ID with sub-unit
901906
TypeName="Temp+Hum",
902907
Used=1 if self.auto_enable_devices else 0
903908
).Create()
904-
Domoticz.Debug(f"Successfully created thermostat sensor for {device_name}")
909+
Domoticz.Log(f"Created thermostat sensor: {device_name} (Unit {unit}, Sub-unit {subunit})")
905910
except Exception as e:
906-
Domoticz.Debug(f"Device ({unit}:{subunit}) already exists or creation failed: {e}")
911+
Domoticz.Debug(f"Thermostat sensor ({unit}:{subunit}) already exists")
912+
else:
913+
Domoticz.Debug(f"Skipping thermostat sensor ({unit}:{subunit}) - already attempted")
907914

908915
# Extract state values
909916
cur_temp = state.get('cur_temp_c')

0 commit comments

Comments
 (0)