Skip to content

Commit 14f8cdd

Browse files
authored
Remove unused code (#465)
* Remove unused code * Remove tests * Remove test * Remove merge
1 parent f585f80 commit 14f8cdd

File tree

4 files changed

+0
-209
lines changed

4 files changed

+0
-209
lines changed

pytradfri/command.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import annotations
33

44
from collections.abc import Callable
5-
from copy import deepcopy
65
from typing import Any, Generic, TypeVar
76

87
T = TypeVar("T")
@@ -99,45 +98,6 @@ def url(self, host: str) -> str:
9998
"""Generate url for coap client."""
10099
return f"coaps://{host}:5684/{self.path_str}"
101100

102-
def _merge(
103-
self, a_dict: dict[str, Any] | None, b_dict: dict[str, Any] | None
104-
) -> dict[str, Any] | None:
105-
"""Merge a into b."""
106-
if a_dict is None or b_dict is None:
107-
return None
108-
for key, value in a_dict.items():
109-
if isinstance(value, dict):
110-
item = b_dict.setdefault(key, {})
111-
self._merge(value, item)
112-
elif isinstance(value, list):
113-
item = b_dict.setdefault(key, [{}])
114-
if len(value) == 1 and isinstance(value[0], dict):
115-
self._merge(value[0], item[0])
116-
else:
117-
b_dict[key] = value
118-
else:
119-
b_dict[key] = value
120-
return b_dict
121-
122-
def combine_data(self, command2: Command[Any] | None) -> None:
123-
"""Combine data for this command with another."""
124-
if command2 is None:
125-
return
126-
self._data = self._merge(
127-
command2._data, self._data # pylint: disable=protected-access
128-
)
129-
130-
def __add__(self, other: Command[Any] | None) -> Command[T]:
131-
"""Add Command to this Command."""
132-
if other is None:
133-
return deepcopy(self)
134-
if isinstance(other, self.__class__):
135-
new_obj = deepcopy(self)
136-
new_obj.combine_data(other)
137-
return new_obj
138-
msg = f"unsupported operand type(s) for '{self.__class__}' and '{type(other)}'"
139-
raise (TypeError(msg))
140-
141101
def __repr__(self) -> str:
142102
"""Return the representation."""
143103
if self.data is None:

pytradfri/smart_task.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,6 @@ def state(self) -> bool:
267267
"""Return state of start action task."""
268268
return self.raw.state == 1
269269

270-
@property
271-
def devices(self) -> list[StartActionItem]:
272-
"""Return state of start action task."""
273-
return [
274-
StartActionItem(self.smart_task, i, self.state, self.path, self.raw)
275-
for i in range(len(self.raw.root_start_action))
276-
]
277-
278270
@property
279271
def raw(self) -> RootStartActionResponse:
280272
"""Return raw data that it represents."""

tests/test_command.py

Lines changed: 0 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -54,145 +54,6 @@ def test_url():
5454
assert url == "coaps://host:5684/path1/path2"
5555

5656

57-
def test_combining_mutates():
58-
"""Test combining mutates."""
59-
DATA_INT = {"key_int": 0}
60-
DATA_INT2 = {"key_int_2": 1}
61-
COMBINED_INT = {"key_int": 0, "key_int_2": 1}
62-
63-
command1 = Command("method", "path", DATA_INT)
64-
command2 = Command("method", "path", DATA_INT2)
65-
combined = command1 + command2
66-
67-
# Adding shouldn't mutate the original commands
68-
assert command1._data == DATA_INT
69-
assert command2._data == DATA_INT2
70-
assert combined._data == COMBINED_INT
71-
72-
# Combining should mutate the original command
73-
command1.combine_data(command2)
74-
assert command1._data == COMBINED_INT
75-
assert command2._data == DATA_INT2
76-
77-
78-
def test_combining_with_none():
79-
"""Test combining with nothing."""
80-
DATA_INT = {"key_int": 0}
81-
82-
command1 = Command("method", "path", DATA_INT)
83-
combined = command1 + None
84-
85-
assert combined._data == DATA_INT
86-
87-
# Combining should mutate the original command
88-
command1.combine_data(None)
89-
assert command1._data == DATA_INT
90-
91-
92-
def test_combining_integer_keys():
93-
"""Test combining integer keys."""
94-
DATA_INT = {"key_int": 0}
95-
DATA_INT_SAME_KEY = {"key_int": 1}
96-
DATA_INT2 = {"key_int_2": 1}
97-
COMBINED_INT = {"key_int": 0, "key_int_2": 1}
98-
99-
command1 = Command("method", "path", DATA_INT)
100-
command2 = Command("method", "path", DATA_INT2)
101-
combined = command1 + command2
102-
assert combined._data == COMBINED_INT
103-
104-
command1 = Command("method", "path", DATA_INT)
105-
command2 = Command("method", "path", DATA_INT_SAME_KEY)
106-
# We should always take the last key if we can't merge
107-
combined = command1 + command2
108-
assert combined._data == DATA_INT_SAME_KEY
109-
110-
111-
def test_combining_string_keys():
112-
"""Test combining simple keys."""
113-
DATA_STRING = {"key_string": "a"}
114-
DATA_STRING_SAME_KEY = {"key_string": "same"}
115-
DATA_STRING2 = {"key_string_2": "b"}
116-
COMBINED_STRING = {"key_string": "a", "key_string_2": "b"}
117-
118-
command1 = Command("method", "path", DATA_STRING)
119-
command2 = Command("method", "path", DATA_STRING2)
120-
combined = command1 + command2
121-
assert combined._data == COMBINED_STRING
122-
123-
command1 = Command("method", "path", DATA_STRING)
124-
command2 = Command("method", "path", DATA_STRING_SAME_KEY)
125-
# We should always take the last key if we can't merge
126-
combined = command1 + command2
127-
assert combined._data == DATA_STRING_SAME_KEY
128-
129-
130-
def test_combining_dict_keys():
131-
"""Test combining dict keys."""
132-
DATA_EMPTY_DICT = {"key_dict": {}}
133-
DATA_DICT_INT = {"key_dict": {"key_int": 0}}
134-
DATA_DICT_STRING = {"key_dict": {"key_string": "a"}}
135-
DATA_DICT_STRING2 = {"key_dict": {"key_string": "b"}}
136-
DATA_DICT_INTSTRING = {"key_dict": {"key_int": 0, "key_string": "a"}}
137-
138-
command1 = Command("method", "path", DATA_EMPTY_DICT)
139-
command2 = Command("method", "path", DATA_DICT_INT)
140-
combined = command1 + command2
141-
assert combined._data == DATA_DICT_INT
142-
143-
command1 = Command("method", "path", DATA_DICT_INT)
144-
command2 = Command("method", "path", DATA_DICT_STRING)
145-
combined = command1 + command2
146-
assert combined._data == DATA_DICT_INTSTRING
147-
148-
command1 = Command("method", "path", DATA_DICT_STRING)
149-
command2 = Command("method", "path", DATA_DICT_STRING2)
150-
combined = command1 + command2
151-
assert combined._data == DATA_DICT_STRING2
152-
153-
command1 = Command("method", "path", DATA_DICT_INT)
154-
command2 = Command("method", "path", DATA_DICT_STRING2)
155-
command3 = Command("method", "path", DATA_DICT_STRING)
156-
combined = command1 + command2 + command3
157-
assert combined._data == DATA_DICT_INTSTRING
158-
159-
160-
def test_combining_list_keys():
161-
"""Test combining simple list keys."""
162-
DATA_EMPTY_LIST = {"key_list": []}
163-
DATA_INT_LIST1 = {"key_list": [0, 1, 2]}
164-
DATA_INT_LIST2 = {"key_list": [10, 11, 12]}
165-
166-
command1 = Command("method", "path", DATA_EMPTY_LIST)
167-
command2 = Command("method", "path", DATA_INT_LIST1)
168-
combined = command1 + command2
169-
assert combined._data == DATA_INT_LIST1
170-
171-
# Duplicated keys are replaced if not dicts
172-
command1 = Command("method", "path", DATA_INT_LIST1)
173-
command2 = Command("method", "path", DATA_INT_LIST2)
174-
combined = command1 + command2
175-
assert combined._data == DATA_INT_LIST2
176-
177-
178-
def test_combining_listed_dict_keys():
179-
"""Test combining of listed dict keys."""
180-
DATA_EMPTY_DICT = {"key_ldict": [{}]}
181-
DATA_DICT_INT = {"key_ldict": [{"key_int": 0}]}
182-
DATA_DICT_STRING = {"key_ldict": [{"key_string": "a"}]}
183-
DATA_DICT_INTSTRING = {"key_ldict": [{"key_int": 0, "key_string": "a"}]}
184-
185-
command1 = Command("method", "path", DATA_EMPTY_DICT)
186-
command2 = Command("method", "path", DATA_DICT_INT)
187-
combined = command1 + command2
188-
assert combined._data == DATA_DICT_INT
189-
190-
command1 = Command("method", "path", DATA_DICT_INT)
191-
command2 = Command("method", "path", DATA_DICT_STRING)
192-
combined = command1 + command2
193-
assert combined._data == DATA_DICT_INTSTRING
194-
195-
19657
def test_add_unsupported():
19758
"""Test add unsupported causes error."""
19859
command1 = Command("method", "path", {})

tests/test_smart_task.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,6 @@ def test_smart_task_info():
9898
assert task.dimmer == 254
9999

100100

101-
def test_smart_task_set_start_action_dimmer():
102-
"""Test start dimmer."""
103-
gateway = Gateway()
104-
105-
cmd = (
106-
SmartTask(gateway, TASK).start_action.devices[0].item_controller.set_dimmer(30)
107-
)
108-
109-
assert cmd.method == "put"
110-
assert cmd.path == ["15010", "317094"]
111-
assert cmd.data == {
112-
"9042": {
113-
"15013": [
114-
{"5712": 18000, "5851": 30, "9003": 65537},
115-
{"5712": 18000, "5851": 254, "9003": 65538},
116-
{"5712": 19000, "5851": 230, "9003": 65539},
117-
],
118-
"5850": 1,
119-
}
120-
}
121-
122-
123101
def test_smart_task_bit_choices():
124102
"""Test smart task with bit choices."""
125103
assert WEEKDAYS.get_selected_values(3) == ["Monday", "Tuesday"]

0 commit comments

Comments
 (0)