Просмотр исходного кода

Merge branch 'homeassistant-goldair-climate'

Merge in Release Candidate 0.1.0-rc
Jason Rumney 5 лет назад
Родитель
Сommit
171219a278

+ 6 - 7
.devcontainer/devcontainer.json

@@ -4,12 +4,7 @@
   "context": "..",
   "appPort": ["8123:8123"],
   "postCreateCommand": "dc install",
-  "runArgs": [
-    "-e",
-    "GIT_EDITOR=code --wait",
-    "-v",
-    "${env:HOME}${env:USERPROFILE}/.ssh:/tmp/.ssh"
-  ],
+  "runArgs": ["-e", "GIT_EDITOR=code --wait"],
   "extensions": [
     "ms-python.python",
     "visualstudioexptteam.vscodeintellicode",
@@ -27,5 +22,9 @@
     "editor.formatOnType": true,
     "files.trimTrailingWhitespace": true,
     "terminal.integrated.shell.linux": "/bin/bash"
-  }
+  },
+  "mounts": [
+    "source=${env:HOME}${env:USERPROFILE}/.ssh,target=/tmp/.ssh,type=bind,consistency=cached",
+    "source=${localWorkspaceFolder}/config,target=/config,type=bind,consistency=cached"
+  ]
 }

+ 21 - 0
.github/workflows/linting.yml

@@ -0,0 +1,21 @@
+name: Linting
+
+on: [push, pull_request]
+
+jobs:
+  lint:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+
+      - name: Setup Python
+        uses: actions/setup-python@v1
+        with:
+          python-version: 3.7
+
+      - name: Install dependencies
+        run: pip install --pre -r requirements.txt
+      - name: isort
+        run: isort --recursive --diff
+      - name: Black
+        run: black --check .

+ 2 - 0
.gitignore

@@ -1,3 +1,5 @@
 /.idea/
 /.vscode/
 __pycache__/
+/config/
+*.zip

+ 5 - 0
.vscode/settings.json

@@ -0,0 +1,5 @@
+{
+  "files.exclude": {
+    "config/custom_components/goldair_climate": true
+  }
+}

+ 1 - 1
.vscode/tasks.json

@@ -10,7 +10,7 @@
     {
       "label": "Run Home Assistant on port 8123",
       "type": "shell",
-      "command": "container start",
+      "command": "pkill hass;container start",
       "problemMatcher": []
     },
     {

+ 16 - 0
build-release.sh

@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+
+set -ex
+
+ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
+TEMP_DIR=`mktemp -d`
+CWD=`pwd`
+
+cd $TEMP_DIR
+cp -r "$ROOT_DIR/custom_components/goldair_climate" .
+cd goldair_climate
+rm -rf __pycache__ */__pycache__
+zip -r homeassistant-goldair-climate * .translations
+cp homeassistant-goldair-climate.zip "$CWD"
+cd "$CWD"
+rm -rf $TEMP_DIR

+ 1 - 1
custom_components/tuya_local/__init__.py

@@ -35,7 +35,7 @@ from .config_flow import ConfigFlowHandler
 
 _LOGGER = logging.getLogger(__name__)
 
-VERSION = "0.0.8"
+VERSION = "0.1.0"
 
 CONFIG_SCHEMA = vol.Schema(
     {DOMAIN: vol.All(cv.ensure_list, [vol.Schema(individual_config_schema())])},

+ 2 - 2
custom_components/tuya_local/climate.py

@@ -12,7 +12,7 @@ from .const import (
     CONF_TYPE_HEATER,
     CONF_TYPE_KOGAN_HEATER,
     CONF_CLIMATE,
-    CONF_TYPE_AUTO
+    CONF_TYPE_AUTO,
 )
 from .dehumidifier.climate import GoldairDehumidifier
 from .fan.climate import GoldairFan
@@ -24,7 +24,7 @@ from .kogan_heater.climate import KoganHeater
 async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
     """Set up the Goldair climate device according to its type."""
     data = hass.data[DOMAIN][discovery_info[CONF_DEVICE_ID]]
-    device = data['device']
+    device = data["device"]
 
     if discovery_info[CONF_TYPE] == CONF_TYPE_AUTO:
         discovery_info[CONF_TYPE] = await device.async_inferred_type()

+ 47 - 14
custom_components/tuya_local/configuration.py

@@ -1,12 +1,21 @@
 import voluptuous as vol
 from homeassistant.const import CONF_NAME, CONF_HOST
 
-from .const import (CONF_DEVICE_ID, CONF_LOCAL_KEY, CONF_TYPE,
-                    CONF_TYPE_HEATER, CONF_TYPE_DEHUMIDIFIER,
-                    CONF_TYPE_FAN, CONF_TYPE_GECO_HEATER,
-                    CONF_TYPE_GPCV_HEATER, CONF_TYPE_KOGAN_HEATER,
-                    CONF_CLIMATE, CONF_DISPLAY_LIGHT, CONF_CHILD_LOCK,
-                    CONF_TYPE_AUTO)
+from .const import (
+    CONF_DEVICE_ID,
+    CONF_LOCAL_KEY,
+    CONF_TYPE,
+    CONF_TYPE_HEATER,
+    CONF_TYPE_DEHUMIDIFIER,
+    CONF_TYPE_FAN,
+    CONF_TYPE_GECO_HEATER,
+    CONF_TYPE_GPCV_HEATER,
+    CONF_TYPE_KOGAN_HEATER,
+    CONF_CLIMATE,
+    CONF_DISPLAY_LIGHT,
+    CONF_CHILD_LOCK,
+    CONF_TYPE_AUTO,
+)
 
 INDIVIDUAL_CONFIG_SCHEMA_TEMPLATE = [
     {"key": CONF_NAME, "type": str, "required": True, "option": False},
@@ -15,18 +24,42 @@ INDIVIDUAL_CONFIG_SCHEMA_TEMPLATE = [
     {"key": CONF_LOCAL_KEY, "type": str, "required": True, "option": True},
     {
         "key": CONF_TYPE,
-        "type": vol.In([
-            CONF_TYPE_AUTO, CONF_TYPE_HEATER, CONF_TYPE_DEHUMIDIFIER,
-            CONF_TYPE_FAN, CONF_TYPE_GECO_HEATER, CONF_TYPE_GPCV_HEATER,
-            CONF_TYPE_KOGAN_HEATER
-        ]),
+        "type": vol.In(
+            [
+                CONF_TYPE_AUTO,
+                CONF_TYPE_HEATER,
+                CONF_TYPE_DEHUMIDIFIER,
+                CONF_TYPE_FAN,
+                CONF_TYPE_GECO_HEATER,
+                CONF_TYPE_GPCV_HEATER,
+                CONF_TYPE_KOGAN_HEATER,
+            ]
+        ),
         "required": False,
         "default": CONF_TYPE_AUTO,
         "option": True,
     },
-    {"key": CONF_CLIMATE, "type": bool, "required": False, "default": True, "option": True},
-    {"key": CONF_DISPLAY_LIGHT, "type": bool, "required": False, "default": False, "option": True},
-    {"key": CONF_CHILD_LOCK, "type": bool, "required": False, "default": False, "option": True},
+    {
+        "key": CONF_CLIMATE,
+        "type": bool,
+        "required": False,
+        "default": True,
+        "option": True,
+    },
+    {
+        "key": CONF_DISPLAY_LIGHT,
+        "type": bool,
+        "required": False,
+        "default": False,
+        "option": True,
+    },
+    {
+        "key": CONF_CHILD_LOCK,
+        "type": bool,
+        "required": False,
+        "default": False,
+        "option": True,
+    },
 ]
 
 

+ 16 - 3
custom_components/tuya_local/dehumidifier/climate.py

@@ -9,6 +9,7 @@ from homeassistant.components.climate.const import (
     ATTR_PRESET_MODE,
     FAN_HIGH,
     FAN_LOW,
+    HVAC_MODE_OFF,
     SUPPORT_FAN_MODE,
     SUPPORT_PRESET_MODE,
     SUPPORT_TARGET_HUMIDITY,
@@ -85,6 +86,15 @@ class GoldairDehumidifier(ClimateDevice):
             return "mdi:cup-water"
         elif self.defrosting:
             return "mdi:snowflake-melt"
+        elif (
+            self.hvac_mode is not HVAC_MODE_OFF
+            and self.preset_mode is PRESET_DRY_CLOTHES
+        ):
+            return "mdi:tshirt-crew-outline"
+        elif (
+            self.hvac_mode is not HVAC_MODE_OFF and self.preset_mode is PRESET_AIR_CLEAN
+        ):
+            return "mdi:air-purifier"
         else:
             return "mdi:air-humidifier"
 
@@ -106,13 +116,16 @@ class GoldairDehumidifier(ClimateDevice):
     @property
     def target_humidity(self):
         """Return the current target humidity."""
-        return self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_TARGET_HUMIDITY])
+        if self.preset_mode is PRESET_NORMAL:
+            return self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_TARGET_HUMIDITY])
+        else:
+            return None
 
     async def async_set_humidity(self, humidity):
         """Set the device's target humidity."""
-        if self.preset_mode in [PRESET_AIR_CLEAN, PRESET_DRY_CLOTHES]:
+        if self.preset_mode is not PRESET_NORMAL:
             raise ValueError(
-                "Humidity can only be changed while in Normal, Low or High preset modes."
+                "Target humidity can only be changed while in Normal mode."
             )
         humidity = int(
             self._HUMIDITY_STEP * round(float(humidity) / self._HUMIDITY_STEP)

+ 2 - 7
custom_components/tuya_local/geco_heater/climate.py

@@ -32,10 +32,7 @@ class GoldairGECOHeater(ClimateDevice):
         self._support_flags = SUPPORT_FLAGS
 
         self._TEMPERATURE_STEP = 1
-        self._TEMPERATURE_LIMITS = {
-            "min": 15,
-            "max": 35
-        }
+        self._TEMPERATURE_LIMITS = {"min": 15, "max": 35}
 
     @property
     def supported_features(self):
@@ -80,9 +77,7 @@ class GoldairGECOHeater(ClimateDevice):
     @property
     def target_temperature(self):
         """Return the temperature we try to reach."""
-        return self._device.get_property(
-            PROPERTY_TO_DPS_ID[ATTR_TARGET_TEMPERATURE]
-        )
+        return self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_TARGET_TEMPERATURE])
 
     @property
     def target_temperature_step(self):

+ 2 - 7
custom_components/tuya_local/gpcv_heater/climate.py

@@ -35,10 +35,7 @@ class GoldairGPCVHeater(ClimateDevice):
         self._support_flags = SUPPORT_FLAGS
 
         self._TEMPERATURE_STEP = 1
-        self._TEMPERATURE_LIMITS = {
-            "min": 15,
-            "max": 35
-        }
+        self._TEMPERATURE_LIMITS = {"min": 15, "max": 35}
 
     @property
     def supported_features(self):
@@ -83,9 +80,7 @@ class GoldairGPCVHeater(ClimateDevice):
     @property
     def target_temperature(self):
         """Return the temperature we try to reach."""
-        return self._device.get_property(
-            PROPERTY_TO_DPS_ID[ATTR_TARGET_TEMPERATURE]
-        )
+        return self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_TARGET_TEMPERATURE])
 
     @property
     def target_temperature_step(self):

+ 1 - 4
custom_components/tuya_local/gpcv_heater/const.py

@@ -23,7 +23,4 @@ PROPERTY_TO_DPS_ID = {
 }
 
 HVAC_MODE_TO_DPS_MODE = {HVAC_MODE_OFF: False, HVAC_MODE_HEAT: True}
-PRESET_MODE_TO_DPS_MODE = {
-    PRESET_LOW: "Low",
-    PRESET_HIGH: "High"
-}
+PRESET_MODE_TO_DPS_MODE = {PRESET_LOW: "Low", PRESET_HIGH: "High"}

+ 13 - 6
custom_components/tuya_local/light.py

@@ -2,11 +2,18 @@
 Setup for different kinds of Tuya climate devices
 """
 from . import DOMAIN
-from .const import (CONF_DEVICE_ID, CONF_TYPE, CONF_TYPE_DEHUMIDIFIER,
-                    CONF_TYPE_FAN, CONF_TYPE_GECO_HEATER,
-                    CONF_TYPE_GPCV_HEATER, CONF_TYPE_HEATER,
-                    CONF_TYPE_KOGAN_HEATER, CONF_DISPLAY_LIGHT,
-                    CONF_TYPE_AUTO)
+from .const import (
+    CONF_DEVICE_ID,
+    CONF_TYPE,
+    CONF_TYPE_DEHUMIDIFIER,
+    CONF_TYPE_FAN,
+    CONF_TYPE_GECO_HEATER,
+    CONF_TYPE_GPCV_HEATER,
+    CONF_TYPE_HEATER,
+    CONF_TYPE_KOGAN_HEATER,
+    CONF_DISPLAY_LIGHT,
+    CONF_TYPE_AUTO,
+)
 from .dehumidifier.light import GoldairDehumidifierLedDisplayLight
 from .fan.light import GoldairFanLedDisplayLight
 from .heater.light import GoldairHeaterLedDisplayLight
@@ -15,7 +22,7 @@ from .heater.light import GoldairHeaterLedDisplayLight
 async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
     """Set up the Goldair climate device according to its type."""
     data = hass.data[DOMAIN][discovery_info[CONF_DEVICE_ID]]
-    device = data['device']
+    device = data["device"]
 
     if discovery_info[CONF_TYPE] == CONF_TYPE_AUTO:
         discovery_info[CONF_TYPE] = await device.async_inferred_type()

+ 2 - 7
custom_components/tuya_local/manifest.json

@@ -4,12 +4,7 @@
   "documentation": "https://github.com/make-all/tuya-local",
   "issue_tracker": "https://github.com/make-all/tuya-local/issues",
   "dependencies": [],
-  "codeowners": [
-      "@make-all",
-      "@nikrolls"
-  ],
-  "requirements": [
-    "pytuya>=7.0.5"
-  ],
+  "codeowners": ["@make-all", "@nikrolls"],
+  "requirements": ["pytuya>=7.0.5"],
   "config_flow": true
 }

+ 2 - 0
requirements.txt

@@ -0,0 +1,2 @@
+black==19.*
+isort==4.*