mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-04-26 16:46:23 +00:00
pass an ioloop
This commit is contained in:
parent
7d3d105e47
commit
533c6b5ca2
@ -65,9 +65,16 @@ class SmartBulb(SmartDevice):
|
|||||||
protocol: TPLinkSmartHomeProtocol = None,
|
protocol: TPLinkSmartHomeProtocol = None,
|
||||||
context: str = None,
|
context: str = None,
|
||||||
cache_ttl: int = 3,
|
cache_ttl: int = 3,
|
||||||
|
*,
|
||||||
|
ioloop=None,
|
||||||
) -> None:
|
) -> None:
|
||||||
SmartDevice.__init__(
|
SmartDevice.__init__(
|
||||||
self, host=host, protocol=protocol, context=context, cache_ttl=cache_ttl
|
self,
|
||||||
|
host=host,
|
||||||
|
protocol=protocol,
|
||||||
|
context=context,
|
||||||
|
cache_ttl=cache_ttl,
|
||||||
|
ioloop=ioloop,
|
||||||
)
|
)
|
||||||
self.emeter_type = "smartlife.iot.common.emeter"
|
self.emeter_type = "smartlife.iot.common.emeter"
|
||||||
self._device_type = DeviceType.Bulb
|
self._device_type = DeviceType.Bulb
|
||||||
@ -120,7 +127,9 @@ class SmartBulb(SmartDevice):
|
|||||||
|
|
||||||
async def set_light_state(self, state: Dict) -> Dict:
|
async def set_light_state(self, state: Dict) -> Dict:
|
||||||
"""Set the light state."""
|
"""Set the light state."""
|
||||||
return await self._query_helper(self.LIGHT_SERVICE, "transition_light_state", state)
|
return await self._query_helper(
|
||||||
|
self.LIGHT_SERVICE, "transition_light_state", state
|
||||||
|
)
|
||||||
|
|
||||||
async def get_hsv(self) -> Tuple[int, int, int]:
|
async def get_hsv(self) -> Tuple[int, int, int]:
|
||||||
"""Return the current HSV state of the bulb.
|
"""Return the current HSV state of the bulb.
|
||||||
@ -203,10 +212,7 @@ class SmartBulb(SmartDevice):
|
|||||||
raise SmartDeviceException("Bulb does not support colortemp.")
|
raise SmartDeviceException("Bulb does not support colortemp.")
|
||||||
|
|
||||||
valid_temperature_range = await self.get_valid_temperature_range()
|
valid_temperature_range = await self.get_valid_temperature_range()
|
||||||
if (
|
if temp < valid_temperature_range[0] or temp > valid_temperature_range[1]:
|
||||||
temp < valid_temperature_range[0]
|
|
||||||
or temp > valid_temperature_range[1]
|
|
||||||
):
|
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Temperature should be between {} "
|
"Temperature should be between {} "
|
||||||
"and {}".format(*valid_temperature_range)
|
"and {}".format(*valid_temperature_range)
|
||||||
|
@ -91,6 +91,8 @@ class SmartDevice:
|
|||||||
protocol: Optional[TPLinkSmartHomeProtocol] = None,
|
protocol: Optional[TPLinkSmartHomeProtocol] = None,
|
||||||
context: str = None,
|
context: str = None,
|
||||||
cache_ttl: int = 3,
|
cache_ttl: int = 3,
|
||||||
|
*,
|
||||||
|
ioloop=None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create a new SmartDevice instance.
|
"""Create a new SmartDevice instance.
|
||||||
|
|
||||||
@ -113,6 +115,7 @@ class SmartDevice:
|
|||||||
)
|
)
|
||||||
self.cache = defaultdict(lambda: defaultdict(lambda: None))
|
self.cache = defaultdict(lambda: defaultdict(lambda: None))
|
||||||
self._device_type = DeviceType.Unknown
|
self._device_type = DeviceType.Unknown
|
||||||
|
self.ioloop = ioloop or asyncio.get_event_loop()
|
||||||
|
|
||||||
def _result_from_cache(self, target, cmd) -> Optional[Dict]:
|
def _result_from_cache(self, target, cmd) -> Optional[Dict]:
|
||||||
"""Return query result from cache if still fresh.
|
"""Return query result from cache if still fresh.
|
||||||
@ -402,7 +405,9 @@ class SmartDevice:
|
|||||||
if "mac" in sys_info:
|
if "mac" in sys_info:
|
||||||
return str(sys_info["mac"])
|
return str(sys_info["mac"])
|
||||||
elif "mic_mac" in sys_info:
|
elif "mic_mac" in sys_info:
|
||||||
return ":".join(format(s, "02x") for s in bytes.fromhex(sys_info["mic_mac"]))
|
return ":".join(
|
||||||
|
format(s, "02x") for s in bytes.fromhex(sys_info["mic_mac"])
|
||||||
|
)
|
||||||
|
|
||||||
raise SmartDeviceException(
|
raise SmartDeviceException(
|
||||||
"Unknown mac, please submit a bug report with sys_info output."
|
"Unknown mac, please submit a bug report with sys_info output."
|
||||||
|
@ -31,8 +31,10 @@ class SmartPlug(SmartDevice):
|
|||||||
protocol: "TPLinkSmartHomeProtocol" = None,
|
protocol: "TPLinkSmartHomeProtocol" = None,
|
||||||
context: str = None,
|
context: str = None,
|
||||||
cache_ttl: int = 3,
|
cache_ttl: int = 3,
|
||||||
|
*,
|
||||||
|
ioloop=None,
|
||||||
) -> None:
|
) -> None:
|
||||||
SmartDevice.__init__(self, host, protocol, context, cache_ttl)
|
SmartDevice.__init__(self, host, protocol, context, cache_ttl, ioloop=ioloop)
|
||||||
self.emeter_type = "emeter"
|
self.emeter_type = "emeter"
|
||||||
self._device_type = DeviceType.Plug
|
self._device_type = DeviceType.Plug
|
||||||
|
|
||||||
|
@ -37,9 +37,16 @@ class SmartStrip(SmartPlug):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, host: str, protocol: TPLinkSmartHomeProtocol = None, cache_ttl: int = 3
|
self,
|
||||||
|
host: str,
|
||||||
|
protocol: TPLinkSmartHomeProtocol = None,
|
||||||
|
cache_ttl: int = 3,
|
||||||
|
*,
|
||||||
|
ioloop=None
|
||||||
) -> None:
|
) -> None:
|
||||||
SmartPlug.__init__(self, host=host, protocol=protocol, cache_ttl=cache_ttl)
|
SmartPlug.__init__(
|
||||||
|
self, host=host, protocol=protocol, cache_ttl=cache_ttl, ioloop=ioloop
|
||||||
|
)
|
||||||
self.emeter_type = "emeter"
|
self.emeter_type = "emeter"
|
||||||
self._device_type = DeviceType.Strip
|
self._device_type = DeviceType.Strip
|
||||||
self.plugs = {}
|
self.plugs = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user