From fceaa85ed9fad22152ea4d1e7e6f1988a06526fc Mon Sep 17 00:00:00 2001 From: Ivan Suazo Date: Tue, 10 Oct 2023 08:21:13 -0600 Subject: [PATCH 1/3] Add option to override the shutdown command --- custom_components/switchbotremote/climate.py | 6 ++++-- custom_components/switchbotremote/config_flow.py | 2 ++ custom_components/switchbotremote/const.py | 1 + custom_components/switchbotremote/translations/en.json | 3 ++- custom_components/switchbotremote/translations/es.json | 3 ++- custom_components/switchbotremote/translations/it.json | 3 ++- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/custom_components/switchbotremote/climate.py b/custom_components/switchbotremote/climate.py index 574d633..fcfd093 100644 --- a/custom_components/switchbotremote/climate.py +++ b/custom_components/switchbotremote/climate.py @@ -27,6 +27,7 @@ CONF_TEMP_MAX, CONF_TEMP_STEP, CONF_HVAC_MODES, + CONF_OVERRIDE_OFF_COMMAND, ) from .config_flow import DEFAULT_HVAC_MODES @@ -79,6 +80,7 @@ def __init__(self, sb: SupportedRemote, options: dict = {}) -> None: self._max_temp = options.get(CONF_TEMP_MAX, DEFAULT_MAX_TEMP) self._min_temp = options.get(CONF_TEMP_MIN, DEFAULT_MIN_TEMP) self._power_sensor = options.get(CONF_POWER_SENSOR, None) + self._override_off_command = options.get(CONF_OVERRIDE_OFF_COMMAND, True) self._fan_mode = FAN_AUTO self._fan_modes = [ @@ -207,7 +209,7 @@ def set_temperature(self, **kwargs): def set_hvac_mode(self, hvac_mode): """Set new target hvac mode.""" - if hvac_mode == HVACMode.OFF: + if hvac_mode == HVACMode.OFF and self._override_off_command: self.sb.turn("off") self._is_on = False else: @@ -222,7 +224,7 @@ def set_fan_mode(self, fan_mode): self._update_remote() def _update_remote(self): - if (self._hvac_mode != HVACMode.OFF): + if (self._hvac_mode != HVACMode.OFF and self._override_off_command): self.sb.command( "setAll", f"{self.target_temperature},{HVAC_REMOTE_MODES[self.hvac_mode]},{FAN_REMOTE_MODES[self.fan_mode]},{self.power_state}", diff --git a/custom_components/switchbotremote/config_flow.py b/custom_components/switchbotremote/config_flow.py index ba00cc4..b92f623 100644 --- a/custom_components/switchbotremote/config_flow.py +++ b/custom_components/switchbotremote/config_flow.py @@ -42,6 +42,7 @@ CONF_WITH_TEMPERATURE, CONF_ON_COMMAND, CONF_OFF_COMMAND, + CONF_OVERRIDE_OFF_COMMAND, ) DEFAULT_HVAC_MODES = [ @@ -77,6 +78,7 @@ vol.Optional(CONF_POWER_SENSOR, description={"suggested_value": x.get(CONF_POWER_SENSOR)}): selector({"entity": {"filter": {"domain": ["binary_sensor", "input_boolean", "light", "sensor", "switch"]}}}), vol.Optional(CONF_TEMPERATURE_SENSOR, description={"suggested_value": x.get(CONF_TEMPERATURE_SENSOR)}): selector({"entity": {"filter": {"domain": "sensor"}}}), vol.Optional(CONF_HUMIDITY_SENSOR, description={"suggested_value": x.get(CONF_HUMIDITY_SENSOR)}): selector({"entity": {"filter": {"domain": "sensor"}}}), + vol.Optional(CONF_OVERRIDE_OFF_COMMAND, default=x.get(CONF_OVERRIDE_OFF_COMMAND, True)): bool, vol.Optional(CONF_TEMP_MIN, default=x.get(CONF_TEMP_MIN, 16)): int, vol.Optional(CONF_TEMP_MAX, default=x.get(CONF_TEMP_MAX, 30)): int, vol.Optional(CONF_TEMP_STEP, default=x.get(CONF_TEMP_STEP, 1.0)): selector({"number": {"min": 0.1, "max": 2.0, "step": 0.1, "mode": "slider"}}), diff --git a/custom_components/switchbotremote/const.py b/custom_components/switchbotremote/const.py index 12dc041..82cb7e7 100644 --- a/custom_components/switchbotremote/const.py +++ b/custom_components/switchbotremote/const.py @@ -18,6 +18,7 @@ CONF_WITH_TEMPERATURE = "with_temperature" CONF_ON_COMMAND = "on_command" CONF_OFF_COMMAND = "off_command" +CONF_OVERRIDE_OFF_COMMAND = "override_off_command" """Supported Devices""" DIY_AIR_CONDITIONER_TYPE = "DIY Air Conditioner" diff --git a/custom_components/switchbotremote/translations/en.json b/custom_components/switchbotremote/translations/en.json index cbbbb6e..48c321e 100644 --- a/custom_components/switchbotremote/translations/en.json +++ b/custom_components/switchbotremote/translations/en.json @@ -49,7 +49,8 @@ "with_brightness": "Enable brightness control buttons", "with_temperature": "Enable temperature color buttons", "on_command": "On/Off button name", - "off_command": "Name of the Off button in case of independent operation" + "off_command": "Name of the Off button in case of independent operation", + "override_off_command": "Override the native 'off' command" } } } diff --git a/custom_components/switchbotremote/translations/es.json b/custom_components/switchbotremote/translations/es.json index f9eecbb..a52a122 100644 --- a/custom_components/switchbotremote/translations/es.json +++ b/custom_components/switchbotremote/translations/es.json @@ -49,7 +49,8 @@ "with_brightness": "Habilitar botones de control brillo", "with_temperature": "Habilitar botones de color de temperatura", "on_command": "Nombre del botón On/Off", - "off_command": "Nombre del botón Off en caso de accionar independiente" + "off_command": "Nombre del botón Off en caso de accionar independiente", + "override_off_command": "Reemplazar el comando de apagado nativo" } } } diff --git a/custom_components/switchbotremote/translations/it.json b/custom_components/switchbotremote/translations/it.json index b939696..c09dacf 100644 --- a/custom_components/switchbotremote/translations/it.json +++ b/custom_components/switchbotremote/translations/it.json @@ -49,7 +49,8 @@ "with_brightness": "Abilita i pulsanti di controllo della luminosità", "with_temperature": "Abilita i pulsanti colorati della temperatura", "on_command": "Nome del pulsante di accensione/spegnimento", - "off_command": "Nome del pulsante Off in caso di funzionamento indipendente" + "off_command": "Nome del pulsante Off in caso di funzionamento indipendente", + "override_off_command": "Ignora il comando di spegnimento nativo" } } } From b08f2f2188ce3793d10c37b15f0ddcf2d602ce91 Mon Sep 17 00:00:00 2001 From: KiraPC Date: Wed, 11 Oct 2023 12:43:34 +0200 Subject: [PATCH 2/3] added hassfest --- .github/workflows/hacs_check.yaml | 17 +++++++++++++++++ .github/workflows/validate.yaml | 14 +++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/hacs_check.yaml diff --git a/.github/workflows/hacs_check.yaml b/.github/workflows/hacs_check.yaml new file mode 100644 index 0000000..8369e39 --- /dev/null +++ b/.github/workflows/hacs_check.yaml @@ -0,0 +1,17 @@ +name: HACS Action + +on: + push: + pull_request: + schedule: + - cron: "0 0 * * *" + +jobs: + hacs: + name: HACS Action + runs-on: "ubuntu-latest" + steps: + - name: HACS Action + uses: "hacs/action@main" + with: + category: "integration" \ No newline at end of file diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index c422ec3..afbde1a 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -1,18 +1,14 @@ -name: Validate +name: Validate with hassfest on: push: pull_request: schedule: - - cron: "0 0 * * *" - workflow_dispatch: + - cron: '0 0 * * *' jobs: - validate-hacs: + validate: runs-on: "ubuntu-latest" steps: - - uses: "actions/checkout@v3" - - name: HACS validation - uses: "hacs/action@main" - with: - category: "integration" + - uses: "actions/checkout@v3" + - uses: "home-assistant/actions/hassfest@master" \ No newline at end of file From 92d84fb0fa4e656ac227bbb6de5248bb8a4d51df Mon Sep 17 00:00:00 2001 From: KiraPC Date: Wed, 11 Oct 2023 12:47:48 +0200 Subject: [PATCH 3/3] sort manifest keys --- custom_components/switchbotremote/manifest.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/switchbotremote/manifest.json b/custom_components/switchbotremote/manifest.json index 6582151..198ffa6 100644 --- a/custom_components/switchbotremote/manifest.json +++ b/custom_components/switchbotremote/manifest.json @@ -5,12 +5,12 @@ "@KiraPC", "@joshepw" ], - "dependencies": [], - "integration_type": "hub", "config_flow": true, + "dependencies": [], "documentation": "https://github.com/KiraPC/ha-switchbot-remote#readme", - "issue_tracker": "https://github.com/KiraPC/ha-switchbot-remote/issues", + "integration_type": "hub", "iot_class": "cloud_push", + "issue_tracker": "https://github.com/KiraPC/ha-switchbot-remote/issues", "requirements": [ "pyhumps" ],