forked from erwindouna/python-melcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
25 lines (19 loc) · 1.08 KB
/
Copy pathutil.py
File metadata and controls
25 lines (19 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import json
import os
from typing import Any, Dict, Optional
from unittest.mock import AsyncMock, Mock, patch
import src.pymelcloud # Ensure the import reflects the new location
def build_device(device_conf_name: str, device_state_name: str, energy_report: Optional[Dict[Any, Any]]=None):
test_dir = os.path.join(os.path.dirname(__file__), "samples")
with open(os.path.join(test_dir, device_conf_name), "r") as json_file:
device_conf = json.load(json_file)
with open(os.path.join(test_dir, device_state_name), "r") as json_file:
device_state = json.load(json_file)
with patch("src.pymelcloud.client.Client") as _client: # Ensure the patch path reflects the new location
_client.update_confs = AsyncMock()
_client.device_confs.__iter__ = Mock(return_value=[device_conf].__iter__())
_client.fetch_device_units = AsyncMock(return_value=[])
_client.fetch_device_state = AsyncMock(return_value=device_state)
_client.fetch_energy_report = AsyncMock(return_value=energy_report)
client = _client
return device_conf, client