Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 38 additions & 36 deletions custom_components/sonoff/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ def effect(self):

@property
def supported_features(self):
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_EFFECT
if self._is_on:
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_EFFECT

@property
def capability_attributes(self):
Expand All @@ -599,42 +600,43 @@ def state_attributes(self):
}

async def async_turn_on(self, **kwargs) -> None:
if not self._is_on:
payload = {'switch': 'on'}
else:
mode = self._mode

mode = self._mode

br = kwargs.get(ATTR_BRIGHTNESS) or self._brightness or 1
br = int(round((br - 1.0) * (100.0 - 1.0) / 254.0 + 1.0))

ct = kwargs.get(ATTR_COLOR_TEMP) or self._temp or self._ColorMiredsColdest
ct = int(round((self._ColorMiredsWarmest - ct) / (self._ColorMiredsWarmest - self._ColorMiredsColdest) * 255.0))

if (ATTR_BRIGHTNESS in kwargs or ATTR_COLOR_TEMP in kwargs):
mode = 'white'

elif ATTR_EFFECT in kwargs:
mode = next(k for k, v in SONOFF103_MODES.items()
if v == kwargs[ATTR_EFFECT])

if mode == 'nightLight':
br = 5
ct = 0
elif mode == 'read':
br = 50
ct = 0
elif mode == 'computer':
br = 20
ct = 255
elif mode == 'bright':
br = 100
ct = 255

payload = {}
payload['ltype'] = mode

payload[mode] = {
'br': br,
'ct': ct
}
br = kwargs.get(ATTR_BRIGHTNESS) or self._brightness or 1
br = int(round((br - 1.0) * (100.0 - 1.0) / 254.0 + 1.0))

ct = kwargs.get(ATTR_COLOR_TEMP) or self._temp or self._ColorMiredsColdest
ct = int(round((self._ColorMiredsWarmest - ct) / (self._ColorMiredsWarmest - self._ColorMiredsColdest) * 255.0))

if (ATTR_BRIGHTNESS in kwargs or ATTR_COLOR_TEMP in kwargs):
mode = 'white'

elif ATTR_EFFECT in kwargs:
mode = next(k for k, v in SONOFF103_MODES.items()
if v == kwargs[ATTR_EFFECT])

if mode == 'nightLight':
br = 5
ct = 0
elif mode == 'read':
br = 50
ct = 0
elif mode == 'computer':
br = 20
ct = 255
elif mode == 'bright':
br = 100
ct = 255

payload = {}
payload['ltype'] = mode
payload[mode] = {
'br': br,
'ct': ct
}

await self.registry.send(self.deviceid, payload)

Expand Down