Skip to content

Add T315 fixture, tests for humidity&temperature modules #802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 6, 2024
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: 5 additions & 1 deletion kasa/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ def data(self):

def _add_feature(self, feature: Feature):
"""Add module feature."""
feat_name = f"{self._module}_{feature.name}"

def _slugified_name(name):
return name.lower().replace(" ", "_").replace("'", "_")

feat_name = _slugified_name(feature.name)
if feat_name in self._module_features:
raise KasaException("Duplicate name detected %s" % feat_name)
self._module_features[feat_name] = feature
Expand Down
4 changes: 2 additions & 2 deletions kasa/smart/modules/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class TemperatureSensor(SmartModule):
"""Implementation of temperature module."""

REQUIRED_COMPONENT = "humidity"
REQUIRED_COMPONENT = "temperature"
QUERY_GETTER_NAME = "get_comfort_temp_config"

def __init__(self, device: "SmartDevice", module: str):
Expand Down Expand Up @@ -53,7 +53,7 @@ def temperature(self):

@property
def temperature_warning(self) -> bool:
"""Return True if humidity is outside of the wanted range."""
"""Return True if temperature is outside of the wanted range."""
return self._device.sys_info["current_temp_exception"] != 0

@property
Expand Down
2 changes: 1 addition & 1 deletion kasa/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Dict
from unittest.mock import MagicMock

import pytest # type: ignore # see https://github.com/pytest-dev/pytest/issues/3342
import pytest

from kasa import (
DeviceConfig,
Expand Down
30 changes: 14 additions & 16 deletions kasa/tests/device_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from itertools import chain
from typing import Dict, List, Set

import pytest
Expand Down Expand Up @@ -106,6 +107,7 @@
}

HUBS_SMART = {"H100"}
SENSORS_SMART = {"T315"}

WITH_EMETER_IOT = {"HS110", "HS300", "KP115", "KP125", *BULBS_IOT}
WITH_EMETER_SMART = {"P110", "KP125M", "EP25"}
Expand All @@ -121,6 +123,7 @@
.union(STRIPS_SMART)
.union(DIMMERS_SMART)
.union(HUBS_SMART)
.union(SENSORS_SMART)
.union(SWITCHES_SMART)
)
ALL_DEVICES = ALL_DEVICES_IOT.union(ALL_DEVICES_SMART)
Expand Down Expand Up @@ -263,6 +266,9 @@ def parametrize(
hubs_smart = parametrize(
"hubs smart", model_filter=HUBS_SMART, protocol_filter={"SMART"}
)
sensors_smart = parametrize(
"sensors smart", model_filter=SENSORS_SMART, protocol_filter={"SMART.CHILD"}
)
device_smart = parametrize(
"devices smart", model_filter=ALL_DEVICES_SMART, protocol_filter={"SMART"}
)
Expand All @@ -283,6 +289,7 @@ def check_categories():
+ bulb_smart.args[1]
+ dimmers_smart.args[1]
+ hubs_smart.args[1]
+ sensors_smart.args[1]
)
diffs: Set[FixtureInfo] = set(FIXTURE_DATA) - set(categorized_fixtures)
if diffs:
Expand All @@ -299,24 +306,14 @@ def check_categories():

def device_for_fixture_name(model, protocol):
if "SMART" in protocol:
for d in PLUGS_SMART:
if d in model:
return SmartDevice
for d in SWITCHES_SMART:
for d in chain(
PLUGS_SMART, SWITCHES_SMART, STRIPS_SMART, HUBS_SMART, SENSORS_SMART
):
if d in model:
return SmartDevice
for d in BULBS_SMART:
if d in model:
return SmartBulb
for d in DIMMERS_SMART:
for d in chain(BULBS_SMART, DIMMERS_SMART):
if d in model:
return SmartBulb
for d in STRIPS_SMART:
if d in model:
return SmartDevice
for d in HUBS_SMART:
if d in model:
return SmartDevice
else:
for d in STRIPS_IOT:
if d in model:
Expand Down Expand Up @@ -378,7 +375,8 @@ async def get_device_for_fixture(fixture_data: FixtureInfo):
discovery_data = {
"system": {"get_sysinfo": fixture_data.data["system"]["get_sysinfo"]}
}
if discovery_data: # Child devices do not have discovery info

if discovery_data: # Child devices do not have discovery info
d.update_from_discover_info(discovery_data)

await _update_and_close(d)
Expand All @@ -392,7 +390,7 @@ async def get_device_for_fixture_protocol(fixture, protocol):
return await get_device_for_fixture(fixture_info)


@pytest.fixture(params=FIXTURE_DATA, ids=idgenerator)
@pytest.fixture(params=filter_fixtures("main devices"), ids=idgenerator)
async def dev(request):
"""Device fixture.

Expand Down
2 changes: 1 addition & 1 deletion kasa/tests/fixtureinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def filter_fixtures(

data_root_filter: return fixtures containing the supplied top
level key, i.e. discovery_result
protocol_filter: set of protocols to match, IOT or SMART
protocol_filter: set of protocols to match, IOT, SMART, SMART.CHILD
model_filter: set of device models to match
component_filter: filter SMART fixtures that have the provided
component in component_nego details.
Expand Down
1 change: 0 additions & 1 deletion kasa/tests/fixtures/smart/child/.gitkeep

This file was deleted.

Loading