From c1878f82e20d7c5d7a24494b326ca55853fad889 Mon Sep 17 00:00:00 2001 From: Kendell R Date: Thu, 22 Oct 2020 02:43:47 -0700 Subject: [PATCH] Improve GitHub Actions (#97) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Delete hassfest.yaml * Update and rename ci.yaml to tox.yaml * Create combined.yaml * Update hacs.json * Update README.md * Update combined.yaml * Remove unused import * Restored wrongly deleted line in cover.py * Update config_flow.py * Update __init__.py Co-authored-by: Pierre Ståhl Co-authored-by: rospogrigio <49229287+rospogrigio@users.noreply.github.com> --- .github/workflows/combined.yaml | 26 +++++++++++++++++++ .github/workflows/hassfest.yaml | 14 ---------- .github/workflows/{ci.yaml => tox.yaml} | 3 +-- README.md | 1 + custom_components/localtuya/__init__.py | 8 +++--- custom_components/localtuya/binary_sensor.py | 3 +-- custom_components/localtuya/common.py | 19 +++++++------- custom_components/localtuya/config_flow.py | 13 +++++----- custom_components/localtuya/cover.py | 13 +++++----- custom_components/localtuya/discovery.py | 2 +- custom_components/localtuya/fan.py | 8 +++--- custom_components/localtuya/light.py | 10 +++---- .../localtuya/pytuya/__init__.py | 8 +++--- custom_components/localtuya/sensor.py | 5 ++-- custom_components/localtuya/switch.py | 8 ++---- hacs.json | 12 ++++----- 16 files changed, 76 insertions(+), 77 deletions(-) create mode 100644 .github/workflows/combined.yaml delete mode 100644 .github/workflows/hassfest.yaml rename .github/workflows/{ci.yaml => tox.yaml} (88%) diff --git a/.github/workflows/combined.yaml b/.github/workflows/combined.yaml new file mode 100644 index 0000000..8cad813 --- /dev/null +++ b/.github/workflows/combined.yaml @@ -0,0 +1,26 @@ +name: "Validation And Formatting" +on: + push: + pull_request: + schedule: + - cron: '0 0 * * *' +jobs: + ci: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + name: Download repo + with: + fetch-depth: 0 + - uses: actions/setup-python@v2 + name: Setup Python + - uses: actions/cache@v2 + name: Cache + with: + path: | + ~/.cache/pip + key: custom-component-ci + - uses: KTibow/ha-blueprint@stable + name: CI + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/hassfest.yaml b/.github/workflows/hassfest.yaml deleted file mode 100644 index 18c7d19..0000000 --- a/.github/workflows/hassfest.yaml +++ /dev/null @@ -1,14 +0,0 @@ -name: Validate with hassfest - -on: - push: - pull_request: - schedule: - - cron: "0 0 * * *" - -jobs: - validate: - runs-on: "ubuntu-latest" - steps: - - uses: "actions/checkout@v2" - - uses: home-assistant/actions/hassfest@master diff --git a/.github/workflows/ci.yaml b/.github/workflows/tox.yaml similarity index 88% rename from .github/workflows/ci.yaml rename to .github/workflows/tox.yaml index 3ab061e..40ca8d9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/tox.yaml @@ -1,4 +1,4 @@ -name: CI +name: Tox PR CI on: [pull_request] @@ -11,7 +11,6 @@ jobs: runs-on: ${{ matrix.platform }} strategy: matrix: - # https://help.github.com/articles/virtual-environments-for-github-actions platform: - ubuntu-latest python-version: diff --git a/README.md b/README.md index 21d227b..d837161 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ ![logo](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/logo-small.png) A Home Assistant custom Integration for local handling of Tuya-based devices. + Device status is updated receiving push updates from the device instead of polling, so status updates are extremely fast (even if manually operated). The following Tuya device types are currently supported: diff --git a/custom_components/localtuya/__init__.py b/custom_components/localtuya/__init__.py index d2c17cf..b455621 100644 --- a/custom_components/localtuya/__init__.py +++ b/custom_components/localtuya/__init__.py @@ -58,20 +58,20 @@ import asyncio import logging from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.core import HomeAssistant, callback from homeassistant.const import ( CONF_DEVICE_ID, - CONF_PLATFORM, CONF_ENTITIES, CONF_HOST, + CONF_PLATFORM, EVENT_HOMEASSISTANT_STOP, SERVICE_RELOAD, ) +from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.reload import async_integration_yaml_config -from .const import DATA_DISCOVERY, DOMAIN, TUYA_DEVICE -from .config_flow import config_schema from .common import TuyaDevice +from .config_flow import config_schema +from .const import DATA_DISCOVERY, DOMAIN, TUYA_DEVICE from .discovery import TuyaDiscovery _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/localtuya/binary_sensor.py b/custom_components/localtuya/binary_sensor.py index 3b1541d..2eb2cf7 100644 --- a/custom_components/localtuya/binary_sensor.py +++ b/custom_components/localtuya/binary_sensor.py @@ -3,10 +3,9 @@ import logging from functools import partial import voluptuous as vol - from homeassistant.components.binary_sensor import ( - DOMAIN, DEVICE_CLASSES_SCHEMA, + DOMAIN, BinarySensorEntity, ) from homeassistant.const import CONF_DEVICE_CLASS diff --git a/custom_components/localtuya/common.py b/custom_components/localtuya/common.py index 75b6659..9c2d8d9 100644 --- a/custom_components/localtuya/common.py +++ b/custom_components/localtuya/common.py @@ -3,21 +3,20 @@ import asyncio import logging from random import randrange +from homeassistant.const import ( + CONF_DEVICE_ID, + CONF_ENTITIES, + CONF_FRIENDLY_NAME, + CONF_HOST, + CONF_ID, + CONF_PLATFORM, +) from homeassistant.core import callback -from homeassistant.helpers.entity import Entity from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, async_dispatcher_send, ) - -from homeassistant.const import ( - CONF_DEVICE_ID, - CONF_ID, - CONF_FRIENDLY_NAME, - CONF_HOST, - CONF_PLATFORM, - CONF_ENTITIES, -) +from homeassistant.helpers.entity import Entity from . import pytuya from .const import CONF_LOCAL_KEY, CONF_PROTOCOL_VERSION, DOMAIN, TUYA_DEVICE diff --git a/custom_components/localtuya/config_flow.py b/custom_components/localtuya/config_flow.py index dea4d94..d41e80b 100644 --- a/custom_components/localtuya/config_flow.py +++ b/custom_components/localtuya/config_flow.py @@ -2,25 +2,24 @@ import logging from importlib import import_module +import homeassistant.helpers.config_validation as cv import voluptuous as vol - from homeassistant import config_entries, core, exceptions -from homeassistant.core import callback from homeassistant.const import ( - CONF_ENTITIES, - CONF_ID, - CONF_HOST, CONF_DEVICE_ID, + CONF_ENTITIES, CONF_FRIENDLY_NAME, + CONF_HOST, + CONF_ID, CONF_PLATFORM, ) -import homeassistant.helpers.config_validation as cv +from homeassistant.core import callback from . import pytuya from .const import ( # pylint: disable=unused-import + CONF_DPS_STRINGS, CONF_LOCAL_KEY, CONF_PROTOCOL_VERSION, - CONF_DPS_STRINGS, DATA_DISCOVERY, DOMAIN, PLATFORMS, diff --git a/custom_components/localtuya/cover.py b/custom_components/localtuya/cover.py index 2b65009..34011cb 100644 --- a/custom_components/localtuya/cover.py +++ b/custom_components/localtuya/cover.py @@ -4,26 +4,25 @@ import logging from functools import partial import voluptuous as vol - from homeassistant.components.cover import ( - CoverEntity, + ATTR_POSITION, DOMAIN, SUPPORT_CLOSE, SUPPORT_OPEN, - SUPPORT_STOP, SUPPORT_SET_POSITION, - ATTR_POSITION, + SUPPORT_STOP, + CoverEntity, ) +from .common import LocalTuyaEntity, async_setup_entry from .const import ( CONF_COMMANDS_SET, CONF_CURRENT_POSITION_DP, - CONF_SET_POSITION_DP, - CONF_POSITIONING_MODE, CONF_POSITION_INVERTED, + CONF_POSITIONING_MODE, + CONF_SET_POSITION_DP, CONF_SPAN_TIME, ) -from .common import LocalTuyaEntity, async_setup_entry _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/localtuya/discovery.py b/custom_components/localtuya/discovery.py index b019aad..1480d75 100644 --- a/custom_components/localtuya/discovery.py +++ b/custom_components/localtuya/discovery.py @@ -4,8 +4,8 @@ Entirely based on tuya-convert.py from tuya-convert: https://github.com/ct-Open-Source/tuya-convert/blob/master/scripts/tuya-discovery.py """ -import json import asyncio +import json import logging from hashlib import md5 diff --git a/custom_components/localtuya/fan.py b/custom_components/localtuya/fan.py index cc9c389..95eb0b1 100644 --- a/custom_components/localtuya/fan.py +++ b/custom_components/localtuya/fan.py @@ -3,14 +3,14 @@ import logging from functools import partial from homeassistant.components.fan import ( - FanEntity, DOMAIN, - SPEED_OFF, + SPEED_HIGH, SPEED_LOW, SPEED_MEDIUM, - SPEED_HIGH, - SUPPORT_SET_SPEED, + SPEED_OFF, SUPPORT_OSCILLATE, + SUPPORT_SET_SPEED, + FanEntity, ) from .common import LocalTuyaEntity, async_setup_entry diff --git a/custom_components/localtuya/light.py b/custom_components/localtuya/light.py index 4f81744..4e29f30 100644 --- a/custom_components/localtuya/light.py +++ b/custom_components/localtuya/light.py @@ -3,20 +3,16 @@ import logging from functools import partial import voluptuous as vol - -from homeassistant.const import ( - CONF_BRIGHTNESS, - CONF_COLOR_TEMP, -) from homeassistant.components.light import ( - LightEntity, - DOMAIN, ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_HS_COLOR, + DOMAIN, SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, + LightEntity, ) +from homeassistant.const import CONF_BRIGHTNESS, CONF_COLOR_TEMP from .common import LocalTuyaEntity, async_setup_entry from .const import CONF_BRIGHTNESS_LOWER, CONF_BRIGHTNESS_UPPER diff --git a/custom_components/localtuya/pytuya/__init__.py b/custom_components/localtuya/pytuya/__init__.py index 0562bdb..fb4f57b 100644 --- a/custom_components/localtuya/pytuya/__init__.py +++ b/custom_components/localtuya/pytuya/__init__.py @@ -37,15 +37,15 @@ Credits import asyncio import base64 -from hashlib import md5 +import binascii import json import logging -import time -import binascii import struct +import time import weakref -from collections import namedtuple from abc import ABC, abstractmethod +from collections import namedtuple +from hashlib import md5 from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes diff --git a/custom_components/localtuya/sensor.py b/custom_components/localtuya/sensor.py index a5a5d7b..7959b9c 100644 --- a/custom_components/localtuya/sensor.py +++ b/custom_components/localtuya/sensor.py @@ -3,16 +3,15 @@ import logging from functools import partial import voluptuous as vol - -from homeassistant.components.sensor import DOMAIN, DEVICE_CLASSES +from homeassistant.components.sensor import DEVICE_CLASSES, DOMAIN from homeassistant.const import ( CONF_DEVICE_CLASS, CONF_UNIT_OF_MEASUREMENT, STATE_UNKNOWN, ) -from .const import CONF_SCALING from .common import LocalTuyaEntity, async_setup_entry +from .const import CONF_SCALING _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/localtuya/switch.py b/custom_components/localtuya/switch.py index 26d1482..d1b4e05 100644 --- a/custom_components/localtuya/switch.py +++ b/custom_components/localtuya/switch.py @@ -3,12 +3,9 @@ import logging from functools import partial import voluptuous as vol +from homeassistant.components.switch import DOMAIN, SwitchEntity -from homeassistant.components.switch import ( - SwitchEntity, - DOMAIN, -) - +from .common import LocalTuyaEntity, async_setup_entry from .const import ( ATTR_CURRENT, ATTR_CURRENT_CONSUMPTION, @@ -17,7 +14,6 @@ from .const import ( CONF_CURRENT_CONSUMPTION, CONF_VOLTAGE, ) -from .common import LocalTuyaEntity, async_setup_entry _LOGGER = logging.getLogger(__name__) diff --git a/hacs.json b/hacs.json index d1f299c..4b6ec05 100644 --- a/hacs.json +++ b/hacs.json @@ -1,6 +1,6 @@ -{ - "name": "localTuya", - "domains": ["climate","cover", "fan", "light", "sensor", "switch"], - "homeassistant": "0.116.0", - "iot_class": ["Local Push"] -} +{ + "name": "Local Tuya", + "domains": ["climate", "cover", "fan", "light", "sensor", "switch"], + "homeassistant": "0.116.0", + "iot_class": ["Local Push"] +}