@@ -157,6 +157,7 @@ class Sensor(PlatformEntity):
157
157
_attr_native_unit_of_measurement : str | None = None
158
158
_attr_device_class : SensorDeviceClass | None = None
159
159
_attr_state_class : SensorStateClass | None = None
160
+ _skip_creation_if_no_attr_cache : bool = False
160
161
161
162
@classmethod
162
163
def create_platform_entity (
@@ -183,6 +184,12 @@ def create_platform_entity(
183
184
)
184
185
return None
185
186
187
+ if (
188
+ cls ._skip_creation_if_no_attr_cache
189
+ and cluster_handlers [0 ].cluster .get (cls ._attribute_name ) is None
190
+ ):
191
+ return None
192
+
186
193
return cls (unique_id , cluster_handlers , endpoint , device , ** kwargs )
187
194
188
195
def __init__ (
@@ -622,6 +629,7 @@ class ElectricalMeasurement(PollableSensor):
622
629
_attr_device_class : SensorDeviceClass = SensorDeviceClass .POWER
623
630
_attr_state_class : SensorStateClass = SensorStateClass .MEASUREMENT
624
631
_attr_native_unit_of_measurement : str = UnitOfPower .WATT
632
+ _attr_max_attribute_name : str = None
625
633
_div_mul_prefix : str | None = "ac_power"
626
634
627
635
def __init__ (
@@ -636,17 +644,22 @@ def __init__(
636
644
super ().__init__ (unique_id , cluster_handlers , endpoint , device , ** kwargs )
637
645
self ._attr_extra_state_attribute_names : set [str ] = {
638
646
"measurement_type" ,
639
- f" { self ._attribute_name } _max" ,
647
+ self ._max_attribute_name ,
640
648
}
641
649
650
+ @property
651
+ def _max_attribute_name (self ) -> str :
652
+ """Return the max attribute name."""
653
+ return self ._attr_max_attribute_name or f"{ self ._attribute_name } _max"
654
+
642
655
@property
643
656
def state (self ) -> dict [str , Any ]:
644
657
"""Return the state for this sensor."""
645
658
response = super ().state
646
659
if self ._cluster_handler .measurement_type is not None :
647
660
response ["measurement_type" ] = self ._cluster_handler .measurement_type
648
661
649
- max_attr_name = f" { self ._attribute_name } _max"
662
+ max_attr_name = self ._max_attribute_name
650
663
if not hasattr (self ._cluster_handler .cluster .AttributeDefs , max_attr_name ):
651
664
return response
652
665
@@ -705,6 +718,28 @@ class ElectricalMeasurementRMSCurrent(PolledElectricalMeasurement):
705
718
_div_mul_prefix = "ac_current"
706
719
707
720
721
+ @MULTI_MATCH (cluster_handler_names = CLUSTER_HANDLER_ELECTRICAL_MEASUREMENT )
722
+ class ElectricalMeasurementRMSCurrentPhB (ElectricalMeasurementRMSCurrent ):
723
+ """RMS current measurement."""
724
+
725
+ _attribute_name = "rms_current_ph_b"
726
+ _unique_id_suffix = "rms_current_ph_b"
727
+ _attr_translation_key : str = "rms_current_ph_b"
728
+ _skip_creation_if_no_attr_cache = True
729
+ _attr_max_attribute_name : str = "rms_current_max_ph_b"
730
+
731
+
732
+ @MULTI_MATCH (cluster_handler_names = CLUSTER_HANDLER_ELECTRICAL_MEASUREMENT )
733
+ class ElectricalMeasurementRMSCurrentPhC (ElectricalMeasurementRMSCurrent ):
734
+ """RMS current measurement."""
735
+
736
+ _attribute_name : str = "rms_current_ph_c"
737
+ _unique_id_suffix : str = "rms_current_ph_c"
738
+ _attr_translation_key : str = "rms_current_ph_c"
739
+ _skip_creation_if_no_attr_cache = True
740
+ _attr_max_attribute_name : str = "rms_current_max_ph_c"
741
+
742
+
708
743
@MULTI_MATCH (cluster_handler_names = CLUSTER_HANDLER_ELECTRICAL_MEASUREMENT )
709
744
class ElectricalMeasurementRMSVoltage (PolledElectricalMeasurement ):
710
745
"""RMS Voltage measurement."""
@@ -1115,30 +1150,15 @@ class SmartEnergySummationReceived(PolledSmartEnergySummation):
1115
1150
_attribute_name = "current_summ_received"
1116
1151
_unique_id_suffix = "summation_received"
1117
1152
_attr_translation_key : str = "summation_received"
1118
-
1119
- @classmethod
1120
- def create_platform_entity (
1121
- cls : type [Self ],
1122
- unique_id : str ,
1123
- cluster_handlers : list [ClusterHandler ],
1124
- endpoint : Endpoint ,
1125
- device : Device ,
1126
- ** kwargs : Any ,
1127
- ) -> Self | None :
1128
- """Entity Factory.
1129
-
1130
- This attribute only started to be initialized in HA 2024.2.0,
1131
- so the entity would be created on the first HA start after the
1132
- upgrade for existing devices, as the initialization to see if
1133
- an attribute is unsupported happens later in the background.
1134
- To avoid creating unnecessary entities for existing devices,
1135
- wait until the attribute was properly initialized once for now.
1136
- """
1137
- if cluster_handlers [0 ].cluster .get (cls ._attribute_name ) is None :
1138
- return None
1139
- return super ().create_platform_entity (
1140
- unique_id , cluster_handlers , endpoint , device , ** kwargs
1141
- )
1153
+ """
1154
+ This attribute only started to be initialized in HA 2024.2.0,
1155
+ so the entity would be created on the first HA start after the
1156
+ upgrade for existing devices, as the initialization to see if
1157
+ an attribute is unsupported happens later in the background.
1158
+ To avoid creating unnecessary entities for existing devices,
1159
+ wait until the attribute was properly initialized once for now.
1160
+ """
1161
+ _skip_creation_if_no_attr_cache = True
1142
1162
1143
1163
1144
1164
@MULTI_MATCH (cluster_handler_names = CLUSTER_HANDLER_PRESSURE )
0 commit comments