@@ -27,31 +27,35 @@ async def async_setup_entry(
2727) -> None :
2828 """Set up lights."""
2929
30+ coordinator = hass .data [DOMAIN ][config_entry .entry_id ]["coordinator" ]
31+
3032 @callback
3133 def discover (devices ):
3234 """Add new devices to platform."""
33- _setup_entities (devices , async_add_entities )
35+ _setup_entities (devices , async_add_entities , coordinator )
3436
3537 config_entry .async_on_unload (
3638 async_dispatcher_connect (hass , VS_DISCOVERY .format (VS_LIGHTS ), discover )
3739 )
3840
3941 _setup_entities (
40- hass .data [DOMAIN ][config_entry .entry_id ][VS_LIGHTS ], async_add_entities
42+ hass .data [DOMAIN ][config_entry .entry_id ][VS_LIGHTS ],
43+ async_add_entities ,
44+ coordinator ,
4145 )
4246
4347
4448@callback
45- def _setup_entities (devices , async_add_entities ):
49+ def _setup_entities (devices , async_add_entities , coordinator ):
4650 """Check if device is online and add entity."""
4751 entities = []
4852 for dev in devices :
4953 if DEV_TYPE_TO_HA .get (dev .device_type ) in ("walldimmer" , "bulb-dimmable" ):
50- entities .append (VeSyncDimmableLightHA (dev ))
54+ entities .append (VeSyncDimmableLightHA (dev , coordinator ))
5155 if DEV_TYPE_TO_HA .get (dev .device_type ) in ("bulb-tunable-white" ,):
52- entities .append (VeSyncTunableWhiteLightHA (dev ))
56+ entities .append (VeSyncTunableWhiteLightHA (dev , coordinator ))
5357 if hasattr (dev , "night_light" ) and dev .night_light :
54- entities .append (VeSyncNightLightHA (dev ))
58+ entities .append (VeSyncNightLightHA (dev , coordinator ))
5559
5660 async_add_entities (entities , update_before_add = True )
5761
@@ -84,6 +88,10 @@ def _ha_brightness_to_vesync(ha_brightness):
8488class VeSyncBaseLight (VeSyncDevice , LightEntity ):
8589 """Base class for VeSync Light Devices Representations."""
8690
91+ def __init_ (self , light , coordinator ):
92+ """Initialize the VeSync light device."""
93+ super ().__init__ (light , coordinator )
94+
8795 @property
8896 def brightness (self ):
8997 """Get light brightness."""
@@ -132,6 +140,10 @@ def turn_on(self, **kwargs):
132140class VeSyncDimmableLightHA (VeSyncBaseLight , LightEntity ):
133141 """Representation of a VeSync dimmable light device."""
134142
143+ def __init__ (self , device , coordinator ):
144+ """Initialize the VeSync dimmable light device."""
145+ super ().__init__ (device , coordinator )
146+
135147 @property
136148 def color_mode (self ):
137149 """Set color mode for this entity."""
@@ -146,6 +158,10 @@ def supported_color_modes(self):
146158class VeSyncTunableWhiteLightHA (VeSyncBaseLight , LightEntity ):
147159 """Representation of a VeSync Tunable White Light device."""
148160
161+ def __init__ (self , device , coordinator ):
162+ """Initialize the VeSync Tunable White Light device."""
163+ super ().__init__ (device , coordinator )
164+
149165 @property
150166 def color_temp (self ):
151167 """Get device white temperature."""
@@ -197,9 +213,9 @@ def supported_color_modes(self):
197213class VeSyncNightLightHA (VeSyncDimmableLightHA ):
198214 """Representation of the night light on a VeSync device."""
199215
200- def __init__ (self , device ):
216+ def __init__ (self , device , coordinator ):
201217 """Initialize the VeSync device."""
202- super ().__init__ (device )
218+ super ().__init__ (device , coordinator )
203219 self .device = device
204220 self .has_brightness = has_feature (
205221 self .device , "details" , "night_light_brightness"
0 commit comments