forked from make-all/tuya-local
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f25652
commit 25efc86
Showing
22 changed files
with
210 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[run] | ||
branch = True | ||
|
||
[report] | ||
skip_empty = True | ||
include = custom_components/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Python tests | ||
|
||
on: push | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.8] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements-first.txt | ||
pip install -r requirements-dev.txt | ||
- name: Test with pytest | ||
run: pytest --cov=. --cov-config=.coveragerc --cov-report xml:coverage.xml | ||
- name: Track master branch | ||
run: git fetch --no-tags https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY +refs/heads/master:refs/remotes/origin/master | ||
- name: SonarCloud scan | ||
uses: sonarsource/sonarcloud-github-action@master | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
/.vscode/ | ||
__pycache__/ | ||
/config/ | ||
*.zip | ||
*.zip | ||
/.coverage | ||
/coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
homeassistant~=0.110.1 | ||
pycrypto~=2.6.1 | ||
pytuya~=7.0.5 | ||
pytest~=5.4.2 | ||
pytest-cov~=2.9.0 | ||
black~=19.10b0 | ||
isort~=4.3.21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pycrypto~=2.6.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
black==19.* | ||
isort==4.* | ||
pycrypto~=2.6.1 | ||
pytuya~=7.0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sonar.organization=nikrolls | ||
sonar.projectKey=nikrolls_homeassistant-goldair-climate | ||
|
||
sonar.sources=./custom_components/goldair_climate | ||
sonar.tests=./tests | ||
sonar.python.coverage.reportPaths=/github/workspace/coverage.xml |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
GPPH_HEATER_PAYLOAD = { | ||
"1": False, | ||
"2": 25, | ||
"3": 17, | ||
"4": "C", | ||
"6": True, | ||
"12": 0, | ||
"101": "5", | ||
"102": 0, | ||
"103": False, | ||
"104": True, | ||
"105": "auto", | ||
"106": 20, | ||
} | ||
|
||
GPCV_HEATER_PAYLOAD = { | ||
"1": True, | ||
"2": True, | ||
"3": 30, | ||
"4": 25, | ||
"5": 0, | ||
"6": 0, | ||
"7": "Low", | ||
} | ||
|
||
GECO_HEATER_PAYLOAD = {"1": True, "2": True, "3": 30, "4": 25, "5": 0, "6": 0} | ||
|
||
DEHUMIDIFIER_PAYLOAD = { | ||
"1": False, | ||
"2": "0", | ||
"4": 30, | ||
"5": False, | ||
"6": "1", | ||
"7": False, | ||
"11": 0, | ||
"12": "0", | ||
"101": False, | ||
"102": False, | ||
"103": 20, | ||
"104": 78, | ||
"105": False, | ||
} | ||
|
||
FAN_PAYLOAD = {"1": False, "2": "12", "3": "normal", "8": True, "11": "0", "101": False} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from unittest import IsolatedAsyncioTestCase | ||
from unittest.mock import patch | ||
|
||
from custom_components.goldair_climate.const import ( | ||
CONF_TYPE_DEHUMIDIFIER, | ||
CONF_TYPE_FAN, | ||
CONF_TYPE_GECO_HEATER, | ||
CONF_TYPE_GPCV_HEATER, | ||
CONF_TYPE_GPPH_HEATER, | ||
) | ||
from custom_components.goldair_climate.device import GoldairTuyaDevice | ||
|
||
from .const import ( | ||
DEHUMIDIFIER_PAYLOAD, | ||
FAN_PAYLOAD, | ||
GECO_HEATER_PAYLOAD, | ||
GPCV_HEATER_PAYLOAD, | ||
GPPH_HEATER_PAYLOAD, | ||
) | ||
|
||
|
||
class TestDevice(IsolatedAsyncioTestCase): | ||
def setUp(self): | ||
patcher = patch("pytuya.Device") | ||
self.addCleanup(patcher.stop) | ||
self.mock_api = patcher.start() | ||
self.subject = GoldairTuyaDevice( | ||
"Some name", "some_dev_id", "some.ip.address", "some_local_key", None | ||
) | ||
|
||
def test_configures_pytuya_correctly(self): | ||
self.mock_api.assert_called_once_with( | ||
"some_dev_id", "some.ip.address", "some_local_key", "device" | ||
) | ||
self.assertIs(self.subject._api, self.mock_api()) | ||
|
||
def test_name(self): | ||
"""Returns the name given at instantiation.""" | ||
self.assertEqual("Some name", self.subject.name) | ||
|
||
def test_unique_id(self): | ||
"""Returns the unique ID presented by the API class.""" | ||
self.assertIs(self.subject.unique_id, self.mock_api().id) | ||
|
||
def test_device_info(self): | ||
"""Returns generic info plus the unique ID for categorisation.""" | ||
self.assertEqual( | ||
self.subject.device_info, | ||
{ | ||
"identifiers": {("goldair_climate", self.mock_api().id)}, | ||
"name": "Some name", | ||
"manufacturer": "Goldair", | ||
}, | ||
) | ||
|
||
async def test_detects_geco_heater_payload(self): | ||
self.subject._cached_state = GECO_HEATER_PAYLOAD | ||
self.assertEqual( | ||
await self.subject.async_inferred_type(), CONF_TYPE_GECO_HEATER | ||
) | ||
|
||
async def test_detects_gpcv_heater_payload(self): | ||
self.subject._cached_state = GPCV_HEATER_PAYLOAD | ||
self.assertEqual( | ||
await self.subject.async_inferred_type(), CONF_TYPE_GPCV_HEATER | ||
) | ||
|
||
async def test_detects_gpph_heater_payload(self): | ||
self.subject._cached_state = GPPH_HEATER_PAYLOAD | ||
self.assertEqual( | ||
await self.subject.async_inferred_type(), CONF_TYPE_GPPH_HEATER | ||
) | ||
|
||
async def test_detects_dehumidifier_payload(self): | ||
self.subject._cached_state = DEHUMIDIFIER_PAYLOAD | ||
self.assertEqual( | ||
await self.subject.async_inferred_type(), CONF_TYPE_DEHUMIDIFIER | ||
) | ||
|
||
async def test_detects_fan_payload(self): | ||
self.subject._cached_state = FAN_PAYLOAD | ||
self.assertEqual(await self.subject.async_inferred_type(), CONF_TYPE_FAN) |