diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8bec49d..6e59ae4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9] + python-version: [3.6, 3.7, 3.8, 3.9, 3.10, 3.11] steps: - uses: actions/checkout@v2 - run: pip3 install tox diff --git a/pymelcloud/client.py b/pymelcloud/client.py index 0b0a429..c2a5927 100644 --- a/pymelcloud/client.py +++ b/pymelcloud/client.py @@ -186,25 +186,6 @@ async def fetch_device_state(self, device) -> Optional[Dict[Any, Any]]: ) as resp: return await resp.json() - async def fetch_energy_report(self, device) -> Optional[Dict[Any, Any]]: - """Fetch energy report containing today and 1-2 days from the past.""" - device_id = device.device_id - from_str = (datetime.today() - timedelta(days=2)).strftime("%Y-%m-%d") - to_str = (datetime.today() + timedelta(days=2)).strftime("%Y-%m-%d") - - async with self._session.post( - f"{BASE_URL}/EnergyCost/Report", - headers=_headers(self._token), - json={ - "DeviceId": device_id, - "UseCurrency": False, - "FromDate": f"{from_str}T00:00:00", - "ToDate": f"{to_str}T00:00:00" - }, - raise_for_status=True, - ) as resp: - return await resp.json() - async def set_device_state(self, device): """Update device state. diff --git a/pymelcloud/device.py b/pymelcloud/device.py index 4a2e31f..6fdbe11 100644 --- a/pymelcloud/device.py +++ b/pymelcloud/device.py @@ -83,7 +83,6 @@ async def update(self): and c.get("BuildingID") == self.building_id ) self._state = await self._client.fetch_device_state(self) - self._energy_report = await self._client.fetch_energy_report(self) if self._device_units is None and self.access_level != ACCESS_LEVEL.get( "GUEST" @@ -187,26 +186,8 @@ def power(self) -> Optional[bool]: @property def daily_energy_consumed(self) -> Optional[float]: - """Return daily energy consumption for the current day in kWh. - - The value resets at midnight MELCloud time. The logic here is a bit iffy and - fragmented between Device and Client. Here's how it goes: - - Client requests a 5 day report. Today, 2 days from the past and 2 days from - the past. - - MELCloud, with its clock potentially set to a different timezone than the - client, returns a report containing data from a couple of days from the - past and from the current day in MELCloud time. - - Device sums up the date from the last day bucket in the report. - - TLDR: Request some days from the past and some days from the future -> receive - the latest day bucket. - """ - if self._energy_report is None: - return None - - consumption = 0 + """Return None. - for mode in ['Heating', 'Cooling', 'Auto', 'Dry', 'Fan', 'Other']: - consumption += self._energy_report.get(mode, [0.0])[-1] - - return consumption + This operation seems to be off limits. + """ + return None diff --git a/requirements.txt b/requirements.txt index 158b4c1..6dc2b73 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ aiohttp -asynctest pre-commit diff --git a/tests/test_device.py b/tests/test_device.py index b57c538..ee64c84 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -39,33 +39,3 @@ async def test_round_temperature(): assert device.round_temperature(25.00001) == 25.0 assert device.round_temperature(25.49999) == 25.0 assert device.round_temperature(25.5) == 26.0 - -@pytest.mark.asyncio -async def test_energy_report_none_if_no_report(): - device = _build_device("ata_listdevice.json", "ata_get.json") - - await device.update() - - assert device.daily_energy_consumed is None - -def test_energy_report_before_update(): - device = _build_device("ata_listdevice.json", "ata_get.json") - - assert device.daily_energy_consumed is None - -@pytest.mark.asyncio -async def test_round_temperature(): - device = _build_device( - "ata_listdevice.json", - "ata_get.json", - { - "Heating": [0.0, 0.0, 1.0], - "Cooling": [0.0, 0.1, 10.0], - "Dry": [0.2, 0.0, 100.0], - "Fan": [0.3, 1000.0], - }, - ) - - await device.update() - - assert device.daily_energy_consumed == 1111.0 diff --git a/tests/util.py b/tests/util.py index d30b3d5..0772703 100644 --- a/tests/util.py +++ b/tests/util.py @@ -2,7 +2,7 @@ import os from typing import Any, Dict, Optional -from asynctest import CoroutineMock, Mock, patch +from unittest.mock import AsyncMock, Mock, patch 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") @@ -13,11 +13,11 @@ def build_device(device_conf_name: str, device_state_name: str, energy_report: O device_state = json.load(json_file) with patch("pymelcloud.client.Client") as _client: - _client.update_confs = CoroutineMock() + _client.update_confs = AsyncMock() _client.device_confs.__iter__ = Mock(return_value=[device_conf].__iter__()) - _client.fetch_device_units = CoroutineMock(return_value=[]) - _client.fetch_device_state = CoroutineMock(return_value=device_state) - _client.fetch_energy_report = CoroutineMock(return_value=energy_report) + _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 diff --git a/tox.ini b/tox.ini index 7ad1f4c..0816799 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=py36,py37,py38,py39,flake8,typing +envlist=py36,py37,py38,py39,py310,py311,flake8,typing [testenv] deps=