Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion kasa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def __getattr__(name):
from . import smart

smart.SmartDevice("127.0.0.1")
smart.SmartPlug("127.0.0.1")
smart.SmartBulb("127.0.0.1")
iot.IotDevice("127.0.0.1")
iot.IotPlug("127.0.0.1")
Expand Down
4 changes: 2 additions & 2 deletions kasa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
)
from kasa.discover import DiscoveryResult
from kasa.iot import IotBulb, IotDevice, IotDimmer, IotLightStrip, IotPlug, IotStrip
from kasa.smart import SmartBulb, SmartDevice, SmartPlug
from kasa.smart import SmartBulb, SmartDevice

try:
from pydantic.v1 import ValidationError
Expand Down Expand Up @@ -72,7 +72,7 @@ def wrapper(message=None, *args, **kwargs):
"iot.dimmer": IotDimmer,
"iot.strip": IotStrip,
"iot.lightstrip": IotLightStrip,
"smart.plug": SmartPlug,
"smart.plug": SmartDevice,
"smart.bulb": SmartBulb,
}

Expand Down
16 changes: 8 additions & 8 deletions kasa/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,32 +194,32 @@ def sys_info(self) -> Dict[str, Any]:
@property
def is_bulb(self) -> bool:
"""Return True if the device is a bulb."""
return self._device_type == DeviceType.Bulb
return self.device_type == DeviceType.Bulb

@property
def is_light_strip(self) -> bool:
"""Return True if the device is a led strip."""
return self._device_type == DeviceType.LightStrip
return self.device_type == DeviceType.LightStrip

@property
def is_plug(self) -> bool:
"""Return True if the device is a plug."""
return self._device_type == DeviceType.Plug
return self.device_type == DeviceType.Plug

@property
def is_strip(self) -> bool:
"""Return True if the device is a strip."""
return self._device_type == DeviceType.Strip
return self.device_type == DeviceType.Strip

@property
def is_strip_socket(self) -> bool:
"""Return True if the device is a strip socket."""
return self._device_type == DeviceType.StripSocket
return self.device_type == DeviceType.StripSocket

@property
def is_dimmer(self) -> bool:
"""Return True if the device is a dimmer."""
return self._device_type == DeviceType.Dimmer
return self.device_type == DeviceType.Dimmer

@property
def is_dimmable(self) -> bool:
Expand Down Expand Up @@ -354,9 +354,9 @@ async def set_alias(self, alias: str):

def __repr__(self):
if self._last_update is None:
return f"<{self._device_type} at {self.host} - update() needed>"
return f"<{self.device_type} at {self.host} - update() needed>"
return (
f"<{self._device_type} model {self.model} at {self.host}"
f"<{self.device_type} model {self.model} at {self.host}"
f" ({self.alias}), is_on: {self.is_on}"
f" - dev specific: {self.state_information}>"
)
6 changes: 3 additions & 3 deletions kasa/device_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
BaseProtocol,
BaseTransport,
)
from .smart import SmartBulb, SmartPlug
from .smart import SmartBulb, SmartDevice
from .smartprotocol import SmartProtocol
from .xortransport import XorTransport

Expand Down Expand Up @@ -135,10 +135,10 @@ def get_device_class_from_sys_info(info: Dict[str, Any]) -> Type[IotDevice]:
def get_device_class_from_family(device_type: str) -> Optional[Type[Device]]:
"""Return the device class from the type name."""
supported_device_types: Dict[str, Type[Device]] = {
"SMART.TAPOPLUG": SmartPlug,
"SMART.TAPOPLUG": SmartDevice,
"SMART.TAPOBULB": SmartBulb,
"SMART.TAPOSWITCH": SmartBulb,
"SMART.KASAPLUG": SmartPlug,
"SMART.KASAPLUG": SmartDevice,
"SMART.KASASWITCH": SmartBulb,
"IOT.SMARTPLUGSWITCH": IotPlug,
"IOT.SMARTBULB": IotBulb,
Expand Down
3 changes: 1 addition & 2 deletions kasa/smart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
from .smartbulb import SmartBulb
from .smartchilddevice import SmartChildDevice
from .smartdevice import SmartDevice
from .smartplug import SmartPlug

__all__ = ["SmartDevice", "SmartPlug", "SmartBulb", "SmartChildDevice"]
__all__ = ["SmartDevice", "SmartBulb", "SmartChildDevice"]
25 changes: 25 additions & 0 deletions kasa/smart/smartdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,28 @@ async def factory_reset(self) -> None:
Note, this does not downgrade the firmware.
"""
await self.protocol.query("device_reset")

@property
def device_type(self) -> DeviceType:
"""Return the device type."""
if self._device_type is not DeviceType.Unknown:
return self._device_type

if self.children:
if "SMART.TAPOHUB" in self.sys_info["type"]:
pass # TODO: placeholder for future hub PR
else:
self._device_type = DeviceType.Strip
elif "light_strip" in self._components:
self._device_type = DeviceType.LightStrip
elif "dimmer_calibration" in self._components:
self._device_type = DeviceType.Dimmer
elif "brightness" in self._components:
self._device_type = DeviceType.Bulb
elif "PLUG" in self.sys_info["type"]:
self._device_type = DeviceType.Plug
else:
_LOGGER.warning("Unknown device type, falling back to plug")
self._device_type = DeviceType.Plug

return self._device_type
37 changes: 0 additions & 37 deletions kasa/smart/smartplug.py

This file was deleted.

9 changes: 4 additions & 5 deletions kasa/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)
from kasa.iot import IotBulb, IotDimmer, IotLightStrip, IotPlug, IotStrip
from kasa.protocol import BaseTransport
from kasa.smart import SmartBulb, SmartPlug
from kasa.smart import SmartBulb, SmartDevice
from kasa.xortransport import XorEncryption

from .fakeprotocol_iot import FakeIotProtocol
Expand Down Expand Up @@ -108,7 +108,6 @@
"EP25",
"KS205",
"P125M",
"P135",
"S505",
"TP15",
}
Expand All @@ -121,7 +120,7 @@
STRIPS = {*STRIPS_IOT, *STRIPS_SMART}

DIMMERS_IOT = {"ES20M", "HS220", "KS220M", "KS230", "KP405"}
DIMMERS_SMART = {"S500D"}
DIMMERS_SMART = {"S500D", "P135"}
DIMMERS = {
*DIMMERS_IOT,
*DIMMERS_SMART,
Expand Down Expand Up @@ -346,7 +345,7 @@ def device_for_file(model, protocol):
if protocol == "SMART":
for d in PLUGS_SMART:
if d in model:
return SmartPlug
return SmartDevice
for d in BULBS_SMART:
if d in model:
return SmartBulb
Expand All @@ -355,7 +354,7 @@ def device_for_file(model, protocol):
return SmartBulb
for d in STRIPS_SMART:
if d in model:
return SmartPlug
return SmartDevice
else:
for d in STRIPS_IOT:
if d in model:
Expand Down
3 changes: 0 additions & 3 deletions kasa/tests/test_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ async def test_led(dev):
@plug_smart
async def test_plug_device_info(dev):
assert dev._info is not None
# PLUG_SCHEMA(dev.sys_info)

assert dev.model is not None

assert dev.device_type == DeviceType.Plug or dev.device_type == DeviceType.Strip
# assert dev.is_plug or dev.is_strip
27 changes: 27 additions & 0 deletions kasa/tests/test_smartdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,21 @@

import kasa
from kasa import Credentials, Device, DeviceConfig, KasaException
from kasa.device_type import DeviceType
from kasa.exceptions import SmartErrorCode
from kasa.iot import IotDevice
from kasa.smart import SmartChildDevice, SmartDevice

from .conftest import (
bulb,
device_iot,
device_smart,
dimmer,
handle_turn_on,
has_emeter_iot,
lightstrip,
no_emeter_iot,
plug,
turn_on,
)
from .fakeprotocol_iot import FakeIotProtocol
Expand Down Expand Up @@ -416,3 +421,25 @@ def check_mac(x):
},
extra=REMOVE_EXTRA,
)


@dimmer
def test_device_type_dimmer(dev):
assert dev.device_type == DeviceType.Dimmer


@bulb
def test_device_type_bulb(dev):
if dev.is_light_strip:
pytest.skip("bulb has also lightstrips to test the api")
assert dev.device_type == DeviceType.Bulb


@plug
def test_device_type_plug(dev):
assert dev.device_type == DeviceType.Plug


@lightstrip
def test_device_type_lightstrip(dev):
assert dev.device_type == DeviceType.LightStrip