mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
Add bulb valid temperature range (#122)
This commit is contained in:
parent
caa01befd7
commit
c6739daacc
@ -153,13 +153,15 @@ def brightness(dev, brightness):
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument("temperature", type=click.IntRange(2700, 6500), default=None,
|
||||
@click.argument("temperature", type=click.IntRange(2500, 9000), default=None,
|
||||
required=False)
|
||||
@pass_dev
|
||||
def temperature(dev, temperature):
|
||||
"""Get or set color temperature. (Bulb only)"""
|
||||
if temperature is None:
|
||||
click.echo("Color temperature: %s" % dev.color_temp)
|
||||
if dev.valid_temperature_range != (0, 0):
|
||||
click.echo("(min: %s, max: %s)" % dev.valid_temperature_range)
|
||||
else:
|
||||
click.echo("Setting color temperature to %s" % temperature)
|
||||
dev.color_temp = temperature
|
||||
|
@ -1,6 +1,12 @@
|
||||
from pyHS100 import SmartDevice
|
||||
import re
|
||||
from typing import Any, Dict, Optional, Tuple
|
||||
|
||||
TPLINK_KELVIN = {'LB130': (2500, 9000),
|
||||
'LB120': (2700, 6500),
|
||||
'LB230': (2500, 9000),
|
||||
'KB130': (2500, 9000)}
|
||||
|
||||
|
||||
class SmartBulb(SmartDevice):
|
||||
"""Representation of a TP-Link Smart Bulb.
|
||||
@ -78,6 +84,22 @@ class SmartBulb(SmartDevice):
|
||||
"""
|
||||
return bool(self.sys_info['is_variable_color_temp'])
|
||||
|
||||
@property
|
||||
def valid_temperature_range(self) -> Tuple[int, int]:
|
||||
"""
|
||||
Returns the white temperature range (in Kelvin)
|
||||
depending on the bulb model
|
||||
|
||||
:return: White temperature range in Kelvin (minimun, maximum)
|
||||
:rtype: tuple
|
||||
"""
|
||||
if not self.is_variable_color_temp:
|
||||
return (0, 0)
|
||||
for model, temp_range in TPLINK_KELVIN.items():
|
||||
if re.match(model, self.sys_info['model']):
|
||||
return temp_range
|
||||
return (0, 0)
|
||||
|
||||
def get_light_state(self) -> Dict:
|
||||
return self._query_helper("smartlife.iot.smartbulb.lightingservice",
|
||||
"get_light_state")
|
||||
@ -155,6 +177,11 @@ class SmartBulb(SmartDevice):
|
||||
if not self.is_variable_color_temp:
|
||||
return None
|
||||
|
||||
if temp < self.valid_temperature_range[0] or \
|
||||
temp > self.valid_temperature_range[1]:
|
||||
raise ValueError("Temperature should be between {} "
|
||||
"and {}".format(*self.valid_temperature_range))
|
||||
|
||||
light_state = {
|
||||
"color_temp": temp,
|
||||
}
|
||||
|
@ -201,6 +201,13 @@ class TestSmartBulb(TestCase):
|
||||
def test_rssi(self):
|
||||
self.sysinfo_schema({'rssi': self.bulb.rssi}) # wrapping for vol
|
||||
|
||||
def test_temperature_range(self):
|
||||
self.assertEqual(self.bulb.valid_temperature_range, (2500, 9000))
|
||||
with self.assertRaises(ValueError):
|
||||
self.bulb.color_temp = 1000
|
||||
with self.assertRaises(ValueError):
|
||||
self.bulb.color_temp = 10000
|
||||
|
||||
|
||||
class TestSmartBulbLB100(TestSmartBulb):
|
||||
SYSINFO = sysinfo_lb100
|
||||
|
Loading…
Reference in New Issue
Block a user