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
6 changes: 3 additions & 3 deletions kasa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

def __getattr__(name):
if name in deprecated_names:
warn(f"{name} is deprecated", DeprecationWarning, stacklevel=1)
warn(f"{name} is deprecated", DeprecationWarning, stacklevel=2)
return globals()[f"_deprecated_{name}"]
if name in deprecated_smart_devices:
new_class = deprecated_smart_devices[name]
Expand All @@ -112,13 +112,13 @@ def __getattr__(name):
+ f"from package {package_name} instead or use Discover.discover_single()"
+ " and Device.connect() to support new protocols",
DeprecationWarning,
stacklevel=1,
stacklevel=2,
)
return new_class
if name in deprecated_classes:
new_class = deprecated_classes[name]
msg = f"{name} is deprecated, use {new_class.__name__} instead"
warn(msg, DeprecationWarning, stacklevel=1)
warn(msg, DeprecationWarning, stacklevel=2)
return new_class
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

Expand Down
4 changes: 2 additions & 2 deletions kasa/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def __getattr__(self, name):
msg = f"{name} is deprecated"
if module:
msg += f", use: {module} in device.modules instead"
warn(msg, DeprecationWarning, stacklevel=1)
warn(msg, DeprecationWarning, stacklevel=2)
return self.device_type == dep_device_type_attr[1]
# Other deprecated attributes
if (dep_attr := self._deprecated_other_attributes.get(name)) and (
Expand All @@ -556,6 +556,6 @@ def __getattr__(self, name):
dev_or_mod = self.modules[mod] if mod else self
replacing = f"Module.{mod} in device.modules" if mod else replacing_attr
msg = f"{name} is deprecated, use: {replacing} instead"
warn(msg, DeprecationWarning, stacklevel=1)
warn(msg, DeprecationWarning, stacklevel=2)
return getattr(dev_or_mod, replacing_attr)
raise AttributeError(f"Device has no attribute {name!r}")
2 changes: 1 addition & 1 deletion kasa/interfaces/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,6 @@ async def get_monthly_stats(self, *, year=None, kwh=True) -> dict:
def __getattr__(self, name):
if attr := self._deprecated_attributes.get(name):
msg = f"{name} is deprecated, use {attr} instead"
warn(msg, DeprecationWarning, stacklevel=1)
warn(msg, DeprecationWarning, stacklevel=2)
return getattr(self, attr)
raise AttributeError(f"Energy module has no attribute {name!r}")
4 changes: 2 additions & 2 deletions kasa/iot/iotdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,15 +472,15 @@ def timezone(self) -> tzinfo:
async def get_time(self) -> datetime:
"""Return current time from the device, if available."""
msg = "Use `time` property instead, this call will be removed in the future."
warn(msg, DeprecationWarning, stacklevel=1)
warn(msg, DeprecationWarning, stacklevel=2)
return self.time

async def get_timezone(self) -> tzinfo:
"""Return timezone information."""
msg = (
"Use `timezone` property instead, this call will be removed in the future."
)
warn(msg, DeprecationWarning, stacklevel=1)
warn(msg, DeprecationWarning, stacklevel=2)
return self.timezone

@property # type: ignore
Expand Down
6 changes: 3 additions & 3 deletions kasa/tests/fakeprotocol_smart.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ def try_get_child_fixture_info(child_dev_info):
else:
warn(
f"Could not find child SMART fixture for {child_info}",
stacklevel=1,
stacklevel=2,
)
else:
warn(
f"Child is a cameraprotocol which needs to be implemented {child_info}",
stacklevel=1,
stacklevel=2,
)
# Replace parent child infos with the infos from the child fixtures so
# that updates update both
Expand All @@ -223,7 +223,7 @@ async def _handle_control_child(self, params: dict):
if device_id not in self.child_protocols:
warn(
f"Could not find child fixture {device_id} in {self.fixture_name}",
stacklevel=1,
stacklevel=2,
)
return self._handle_control_child_missing(params)

Expand Down