From dee728d00898f368acb3b7dd97e5ad2c8f5b100a Mon Sep 17 00:00:00 2001 From: rospogrigio Date: Fri, 2 Oct 2020 09:48:17 +0200 Subject: [PATCH] Fixed postlund's remarks --- custom_components/localtuya/__init__.py | 4 ++-- custom_components/localtuya/const.py | 4 ++-- custom_components/localtuya/cover.py | 20 +++++++++++-------- .../localtuya/translations/en.json | 12 +++++------ 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/custom_components/localtuya/__init__.py b/custom_components/localtuya/__init__.py index 6ca523f..2feffb4 100644 --- a/custom_components/localtuya/__init__.py +++ b/custom_components/localtuya/__init__.py @@ -22,8 +22,8 @@ localtuya: id: 2 open_close_cmds: ["on_off","open_close"] # Optional, default: "on_off" positioning_mode: ["none","position","fake"] # Optional, default: "none" - currpos_dps: 3 # Optional, required only for "position" mode - setpos_dps: 4 # Optional, required only for "position" mode + currpos_dp: 3 # Optional, required only for "position" mode + setpos_dp: 4 # Optional, required only for "position" mode span_time: 25 # Full movement time: Optional, required only for "fake" mode - platform: fan diff --git a/custom_components/localtuya/const.py b/custom_components/localtuya/const.py index b36b218..882d310 100644 --- a/custom_components/localtuya/const.py +++ b/custom_components/localtuya/const.py @@ -16,8 +16,8 @@ CONF_VOLTAGE = "voltage" # cover CONF_OPENCLOSE_CMDS = "open_close_cmds" CONF_POSITIONING_MODE = "positioning_mode" -CONF_CURRPOS = "currpos_dps" -CONF_SETPOS = "setpos_dps" +CONF_CURRENT_POSITION_DP = "currpos_dp" +CONF_SET_POSITION_DP = "setpos_dp" CONF_SPAN_TIME = "span_time" # sensor diff --git a/custom_components/localtuya/cover.py b/custom_components/localtuya/cover.py index 581801e..a574cb5 100644 --- a/custom_components/localtuya/cover.py +++ b/custom_components/localtuya/cover.py @@ -17,8 +17,8 @@ from homeassistant.const import CONF_ID from .const import ( CONF_OPENCLOSE_CMDS, - CONF_CURRPOS, - CONF_SETPOS, + CONF_CURRENT_POSITION_DP, + CONF_SET_POSITION_DP, CONF_POSITIONING_MODE, CONF_SPAN_TIME, ) @@ -47,8 +47,8 @@ def flow_schema(dps): vol.Optional(CONF_POSITIONING_MODE, default=DEFAULT_POSITIONING_MODE): vol.In( [COVER_MODE_NONE, COVER_MODE_POSITION, COVER_MODE_FAKE] ), - vol.Optional(CONF_CURRPOS): vol.In(dps), - vol.Optional(CONF_SETPOS): vol.In(dps), + vol.Optional(CONF_CURRENT_POSITION_DP): vol.In(dps), + vol.Optional(CONF_SET_POSITION_DP): vol.In(dps), vol.Optional(CONF_SPAN_TIME, default=DEFAULT_SPAN_TIME): vol.All( vol.Coerce(float), vol.Range(min=1.0, max=300.0) ), @@ -155,8 +155,10 @@ class LocaltuyaCover(LocalTuyaEntity, CoverEntity): elif self._config[CONF_POSITIONING_MODE] == COVER_MODE_POSITION: converted_position = int(kwargs[ATTR_POSITION]) - if 0 <= converted_position <= 100 and self.has_config(CONF_SETPOS): - self._device.set_dps(converted_position, self._config[CONF_SETPOS]) + if 0 <= converted_position <= 100 and self.has_config(CONF_SET_POSITION_DP): + self._device.set_dps( + converted_position, self._config[CONF_SET_POSITION_DP] + ) def open_cover(self, **kwargs): """Open the cover.""" @@ -176,7 +178,9 @@ class LocaltuyaCover(LocalTuyaEntity, CoverEntity): def status_updated(self): """Device status was updated.""" self._state = self.dps(self._dps_id) - if self.has_config(CONF_CURRPOS): - self._current_cover_position = self.dps(self._config[CONF_CURRPOS]) + if self.has_config(CONF_CURRENT_POSITION_DP): + self._current_cover_position = self.dps( + self._config[CONF_CURRENT_POSITION_DP] + ) else: self._current_cover_position = 50 diff --git a/custom_components/localtuya/translations/en.json b/custom_components/localtuya/translations/en.json index 78f1098..24ec9f1 100644 --- a/custom_components/localtuya/translations/en.json +++ b/custom_components/localtuya/translations/en.json @@ -48,9 +48,9 @@ "voltage": "Voltage", "open_close_cmds": "Open/Close Commands", "positioning_mode": "Positioning mode", - "currpos_dps": "Current Position dps (Required only if Positioning Mode is 'position')", - "setpos_dps": "Set Position dps (Required only if Positioning Mode is 'position')", - "span_time": "Time for full opening, in secs. (Optional, required only if Positioning Mode is 'fake')", + "currpos_dp": "Current Position (when Position mode is *position*)", + "setpos_dp": "Set Position (when Position Mode is *position*)", + "span_time": "Full opening time, in secs. (when Position Mode is fake*)", "unit_of_measurement": "Unit of Measurement", "device_class": "Device Class", "scaling": "Scaling Factor", @@ -83,9 +83,9 @@ "voltage": "Voltage", "open_close_cmds": "Open/Close Commands", "positioning_mode": "Positioning mode", - "currpos_dps": "Current Position dps (Required only if Positioning Mode is 'position')", - "setpos_dps": "Set Position dps (Required only if Positioning Mode is 'position')", - "span_time": "Time for full opening, in secs. (Optional, required only if Positioning Mode is 'fake')", + "currpos_dp": "Current Position (for *position* mode only)", + "setpos_dp": "Set Position (for *position* mode only)", + "span_time": "Full opening time, in secs. (for *fake* mode only)", "unit_of_measurement": "Unit of Measurement", "device_class": "Device Class", "scaling": "Scaling Factor",