Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
Disable energy report
Browse files Browse the repository at this point in the history
  • Loading branch information
vilppuvuorinen committed Feb 6, 2024
1 parent 8756c36 commit a4a586a
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 0 additions & 19 deletions pymelcloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 4 additions & 23 deletions pymelcloud/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
aiohttp
asynctest
pre-commit
30 changes: 0 additions & 30 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist=py36,py37,py38,py39,flake8,typing
envlist=py36,py37,py38,py39,py310,py311,flake8,typing

[testenv]
deps=
Expand Down

0 comments on commit a4a586a

Please sign in to comment.