Skip to content

Commit

Permalink
Distinguish RGB and RGBW lamps
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrBerchenko committed Feb 16, 2019
1 parent 51ffbdd commit 6993d8f
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions lightify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@
LAST_SEEN_DURATION_MINUTES = 5
NO_RGB_VALUES = (1, 0, 0)
TYPE_LIGHT_TUNABLE_WHITE = 2
TYPE_LIGHT_RGB = 10
TYPE_LIGHT_RGBW = 10

DEFAULT_LUMINANCE = 1
DEFAULT_TEMPERATURE = 2700
MIN_TEMPERATURE_TUNABLE_WHITE = 2700
MAX_TEMPERATURE_TUNABLE_WHITE = 6500
MIN_TEMPERATURE_RGB = 1900
MAX_TEMPERATURE_RGB = 6500
MIN_TEMPERATURE_RGBW = 1900
MAX_TEMPERATURE_RGBW = 6500
MAX_LUMINANCE = 100
MAX_COLOUR = 255

Expand All @@ -87,10 +87,11 @@ class DeviceSubType(Enum):
LIGHT_FIXED_WHITE = 1
LIGHT_TUNABLE_WHITE = 2
LIGHT_RGB = 3
PLUG = 4
CONTACT_SENSOR = 5
MOTION_SENSOR = 6
SWITCH = 7
LIGHT_RGBW = 4
PLUG = 5
SWITCH = 6
CONTACT_SENSOR = 7
MOTION_SENSOR = 8


class DeviceType(Enum):
Expand All @@ -112,9 +113,12 @@ class DeviceType(Enum):
4: {'type': DeviceType.LIGHT,
'subtype': DeviceSubType.LIGHT_FIXED_WHITE,
'name': 'light fixed white'},
8: {'type': DeviceType.LIGHT,
'subtype': DeviceSubType.LIGHT_RGB,
'name': 'light rgb'},
10: {'type': DeviceType.LIGHT,
'subtype': DeviceSubType.LIGHT_RGB,
'name': 'light rgb'},
'subtype': DeviceSubType.LIGHT_RGBW,
'name': 'light rgbw'},
16: {'type': DeviceType.PLUG,
'subtype': DeviceSubType.PLUG,
'name': 'plug'},
Expand Down Expand Up @@ -144,7 +148,7 @@ class DeviceType(Enum):
'name': 'tradfri tunable white',
'min_temp': 2200,
'max_temp': 4000
},
}
}


Expand Down Expand Up @@ -242,9 +246,9 @@ def __init__(self, conn, addr, type_id, type_id_assumed):
self.__devicename = (device_info['name'] if type_id == type_id_assumed
else UNKNOWN_DEVICENAME)

if self.__devicesubtype in (DeviceSubType.CONTACT_SENSOR,
DeviceSubType.MOTION_SENSOR,
DeviceSubType.SWITCH):
if self.__devicesubtype in (DeviceSubType.SWITCH,
DeviceSubType.CONTACT_SENSOR,
DeviceSubType.MOTION_SENSOR):
self.__lum = 0
self.__temp = 0
self.__red = 0
Expand Down Expand Up @@ -274,12 +278,16 @@ def __init__(self, conn, addr, type_id, type_id_assumed):
'min_temp', MIN_TEMPERATURE_TUNABLE_WHITE)
self.__max_temp = device_info.get(
'max_temp', MAX_TEMPERATURE_TUNABLE_WHITE)
elif self.__devicesubtype == DeviceSubType.LIGHT_RGB:
self.__supported_features = set(('on', 'lum', 'rgb'))
self.__min_temp = self.__temp
self.__max_temp = self.__temp
else:
self.__supported_features = set(('on', 'lum', 'temp', 'rgb'))
self.__min_temp = device_info.get('min_temp',
MIN_TEMPERATURE_RGB)
MIN_TEMPERATURE_RGBW)
self.__max_temp = device_info.get('max_temp',
MAX_TEMPERATURE_RGB)
MAX_TEMPERATURE_RGBW)

def name(self):
"""
Expand Down Expand Up @@ -901,10 +909,10 @@ def __init__(self, host, new_device_types=None, log_level=logging.INFO,
'type': <DeviceType instance>,
'subtype': <DeviceSubType instance>,
'name': <name of the device>,
# only for LIGHT_TUNABLE_WHITE and LIGHT_RGB:
# only for LIGHT_TUNABLE_WHITE and LIGHT_RGBW:
'min_temp': <minimum temperature>, # optional, default:
# 2700 (LIGHT_TUNABLE_WHITE)
# 1900 (LIGHT_RGB)
# 1900 (LIGHT_RGBW)
'max_temp': <maximum temperature> # optional, default: 6500
},
...
Expand Down Expand Up @@ -1575,7 +1583,7 @@ def update_all_light_status(self, throttling_interval=None):
if (red, green, blue) == NO_RGB_VALUES:
type_id_assumed = TYPE_LIGHT_TUNABLE_WHITE
else:
type_id_assumed = TYPE_LIGHT_RGB
type_id_assumed = TYPE_LIGHT_RGBW
else:
type_id_assumed = type_id

Expand Down

0 comments on commit 6993d8f

Please sign in to comment.