mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-04-27 00:56:23 +00:00
Improve bulb support (alias, time settings) (#198)
* Fix set_alias and time related functions for bulbs * Fix tests for smartlife.iot.common.timesetting and smartlife.iot.common.system
This commit is contained in:
parent
1803a83ae6
commit
016d030245
@ -91,6 +91,7 @@ class SmartBulb(SmartDevice):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
LIGHT_SERVICE = "smartlife.iot.smartbulb.lightingservice"
|
LIGHT_SERVICE = "smartlife.iot.smartbulb.lightingservice"
|
||||||
|
TIME_SERVICE = "smartlife.iot.common.timesetting"
|
||||||
SET_LIGHT_METHOD = "transition_light_state"
|
SET_LIGHT_METHOD = "transition_light_state"
|
||||||
|
|
||||||
def __init__(self, host: str) -> None:
|
def __init__(self, host: str) -> None:
|
||||||
@ -359,3 +360,12 @@ class SmartBulb(SmartDevice):
|
|||||||
def has_emeter(self) -> bool:
|
def has_emeter(self) -> bool:
|
||||||
"""Return that the bulb has an emeter."""
|
"""Return that the bulb has an emeter."""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
async def set_alias(self, alias: str) -> None:
|
||||||
|
"""Set the device name (alias).
|
||||||
|
|
||||||
|
Overridden to use a different module name.
|
||||||
|
"""
|
||||||
|
return await self._query_helper(
|
||||||
|
"smartlife.iot.common.system", "set_dev_alias", {"alias": alias}
|
||||||
|
)
|
||||||
|
@ -214,6 +214,8 @@ class SmartDevice:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
TIME_SERVICE = "time"
|
||||||
|
|
||||||
def __init__(self, host: str) -> None:
|
def __init__(self, host: str) -> None:
|
||||||
"""Create a new SmartDevice instance.
|
"""Create a new SmartDevice instance.
|
||||||
|
|
||||||
@ -352,7 +354,7 @@ class SmartDevice:
|
|||||||
async def get_time(self) -> Optional[datetime]:
|
async def get_time(self) -> Optional[datetime]:
|
||||||
"""Return current time from the device, if available."""
|
"""Return current time from the device, if available."""
|
||||||
try:
|
try:
|
||||||
res = await self._query_helper("time", "get_time")
|
res = await self._query_helper(self.TIME_SERVICE, "get_time")
|
||||||
return datetime(
|
return datetime(
|
||||||
res["year"],
|
res["year"],
|
||||||
res["month"],
|
res["month"],
|
||||||
@ -366,7 +368,7 @@ class SmartDevice:
|
|||||||
|
|
||||||
async def get_timezone(self) -> Dict:
|
async def get_timezone(self) -> Dict:
|
||||||
"""Return timezone information."""
|
"""Return timezone information."""
|
||||||
return await self._query_helper("time", "get_timezone")
|
return await self._query_helper(self.TIME_SERVICE, "get_timezone")
|
||||||
|
|
||||||
@property # type: ignore
|
@property # type: ignore
|
||||||
@requires_update
|
@requires_update
|
||||||
|
@ -153,7 +153,7 @@ def get_device_for_file(file):
|
|||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=SUPPORTED_DEVICES)
|
@pytest.fixture(params=SUPPORTED_DEVICES, scope="session")
|
||||||
def dev(request):
|
def dev(request):
|
||||||
"""Device fixture.
|
"""Device fixture.
|
||||||
|
|
||||||
|
@ -252,6 +252,27 @@ def success(res):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
# plugs and bulbs use a different module for time information,
|
||||||
|
# so we define the contents here to avoid repeating ourselves
|
||||||
|
TIME_MODULE = {
|
||||||
|
"get_time": {
|
||||||
|
"year": 2017,
|
||||||
|
"month": 1,
|
||||||
|
"mday": 2,
|
||||||
|
"hour": 3,
|
||||||
|
"min": 4,
|
||||||
|
"sec": 5,
|
||||||
|
},
|
||||||
|
"get_timezone": {
|
||||||
|
"zone_str": "test",
|
||||||
|
"dst_offset": -1,
|
||||||
|
"index": 12,
|
||||||
|
"tz_str": "test2",
|
||||||
|
},
|
||||||
|
"set_timezone": None,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class FakeTransportProtocol(TPLinkSmartHomeProtocol):
|
class FakeTransportProtocol(TPLinkSmartHomeProtocol):
|
||||||
def __init__(self, info):
|
def __init__(self, info):
|
||||||
self.discovery_data = info
|
self.discovery_data = info
|
||||||
@ -393,23 +414,11 @@ class FakeTransportProtocol(TPLinkSmartHomeProtocol):
|
|||||||
"set_light_state": transition_light_state,
|
"set_light_state": transition_light_state,
|
||||||
"get_light_state": light_state,
|
"get_light_state": light_state,
|
||||||
},
|
},
|
||||||
"time": {
|
"smartlife.iot.common.system": {
|
||||||
"get_time": {
|
"set_dev_alias": set_alias,
|
||||||
"year": 2017,
|
|
||||||
"month": 1,
|
|
||||||
"mday": 2,
|
|
||||||
"hour": 3,
|
|
||||||
"min": 4,
|
|
||||||
"sec": 5,
|
|
||||||
},
|
|
||||||
"get_timezone": {
|
|
||||||
"zone_str": "test",
|
|
||||||
"dst_offset": -1,
|
|
||||||
"index": 12,
|
|
||||||
"tz_str": "test2",
|
|
||||||
},
|
|
||||||
"set_timezone": None,
|
|
||||||
},
|
},
|
||||||
|
"time": TIME_MODULE,
|
||||||
|
"smartlife.iot.common.timesetting": TIME_MODULE,
|
||||||
# HS220 brightness, different setter and getter
|
# HS220 brightness, different setter and getter
|
||||||
"smartlife.iot.dimmer": {
|
"smartlife.iot.dimmer": {
|
||||||
"set_brightness": set_hs220_brightness,
|
"set_brightness": set_hs220_brightness,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user