From 4f3c7fd36f2428a15d62fb1aa3a6b39aeb09af24 Mon Sep 17 00:00:00 2001 From: Vincent Le Bourlot Date: Sat, 4 Jun 2022 18:59:00 +0200 Subject: [PATCH] Add current_humidity attribute (#24) * Add current_humidity attribute * fix linter * ignore brand in validate * same * improve extra attributes --- .github/workflows/validate.yml | 1 + .hadolint.yaml | 3 --- custom_components/vesync/humidifier.py | 35 ++++++-------------------- 3 files changed, 8 insertions(+), 31 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index a5c95a9..e66026e 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -13,5 +13,6 @@ jobs: - name: HACS validation uses: "hacs/action@main" with: + ignore: "brands" category: "integration" comment: false diff --git a/.hadolint.yaml b/.hadolint.yaml index 60ecd1f..98bf0cd 100644 --- a/.hadolint.yaml +++ b/.hadolint.yaml @@ -2,6 +2,3 @@ ignored: - SC1090 - SC1091 - -/home/vlb/temp/HAcore/custom_vesync/.venv/local/bin -/home/vlb/temp/HAcore/custom_vesync/.venv/bin \ No newline at end of file diff --git a/custom_components/vesync/humidifier.py b/custom_components/vesync/humidifier.py index ab55a49..c1e96d5 100644 --- a/custom_components/vesync/humidifier.py +++ b/custom_components/vesync/humidifier.py @@ -22,6 +22,7 @@ MAX_HUMIDITY = 80 MIN_HUMIDITY = 30 MODES = [MODE_AUTO, MODE_NORMAL, MODE_SLEEP] +VESYNC_TO_HA_ATTRIBUTES = {"humidity": "current_humidity"} async def async_setup_entry( @@ -113,35 +114,13 @@ class VeSyncHumidifierHA(VeSyncDevice, HumidifierEntity): @property def extra_state_attributes(self): """Return the state attributes of the humidifier.""" + attr = {} - - if "water_lacks" in self.smarthumidifier.details: - attr["water_lacks"] = self.smarthumidifier.details["water_lacks"] - - if "humidity_high" in self.smarthumidifier.details: - attr["humidity_high"] = self.smarthumidifier.details["humidity_high"] - - if "water_tank_lifted" in self.smarthumidifier.details: - attr["water_tank_lifted"] = self.smarthumidifier.details[ - "water_tank_lifted" - ] - - if "automatic_stop_reach_target" in self.smarthumidifier.details: - attr["automatic_stop_reach_target"] = self.smarthumidifier.details[ - "automatic_stop_reach_target" - ] - - if "mist_level" in self.smarthumidifier.details: - attr["mist_level"] = self.smarthumidifier.details["mist_level"] - - if "warm_mist_level" in self.smarthumidifier.details: - attr["warm_mist_level"] = self.smarthumidifier.details["warm_mist_level"] - - if "warm_mist_enabled" in self.smarthumidifier.details: - attr["warm_mist_enabled"] = self.smarthumidifier.details[ - "warm_mist_enabled" - ] - + for k, v in self.smarthumidifier.details.items(): + if k in VESYNC_TO_HA_ATTRIBUTES: + attr[VESYNC_TO_HA_ATTRIBUTES[k]] = v + elif k not in self.state_attributes: + attr[k] = v return attr def set_humidity(self, humidity):