Skip to content

Commit

Permalink
Merge branch 'master' into debug_flow
Browse files Browse the repository at this point in the history
  • Loading branch information
rospogrigio authored Oct 21, 2020
2 parents b8b5a00 + 032fcea commit 098125f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
![logo](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/logo-small.png)

# localtuya-homeassistant

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).

Expand Down
3 changes: 2 additions & 1 deletion custom_components/localtuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
- platform: cover
friendly_name: Device Cover
id: 2
open_close_stop_cmds: # Optional, default: "on_off_stop"
commands_set: # Optional, default: "on_off_stop"
["on_off_stop","open_close_stop","fz_zz_stop","1_2_3"]
positioning_mode: ["none","position","fake"] # Optional, default: "none"
currpos_dp: 3 # Optional, required only for "position" mode
setpos_dp: 4 # Optional, required only for "position" mode
position_inverted: [True,False] # Optional, default: False
span_time: 25 # Full movement time: Optional, required only for "fake" mode
- platform: fan
Expand Down
1 change: 1 addition & 0 deletions custom_components/localtuya/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
CONF_POSITIONING_MODE = "positioning_mode"
CONF_CURRENT_POSITION_DP = "current_position_dp"
CONF_SET_POSITION_DP = "set_position_dp"
CONF_POSITION_INVERTED = "position_inverted"
CONF_SPAN_TIME = "span_time"

# sensor
Expand Down
30 changes: 22 additions & 8 deletions custom_components/localtuya/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
CONF_CURRENT_POSITION_DP,
CONF_SET_POSITION_DP,
CONF_POSITIONING_MODE,
CONF_POSITION_INVERTED,
CONF_SPAN_TIME,
)
from .common import LocalTuyaEntity, async_setup_entry
Expand Down Expand Up @@ -50,6 +51,7 @@ def flow_schema(dps):
),
vol.Optional(CONF_CURRENT_POSITION_DP): vol.In(dps),
vol.Optional(CONF_SET_POSITION_DP): vol.In(dps),
vol.Optional(CONF_POSITION_INVERTED, default=False): bool,
vol.Optional(CONF_SPAN_TIME, default=DEFAULT_SPAN_TIME): vol.All(
vol.Coerce(float), vol.Range(min=1.0, max=300.0)
),
Expand All @@ -70,12 +72,12 @@ def __init__(
super().__init__(device, config_entry, switchid, **kwargs)
self._state = None
self._current_cover_position = None
command_set = DEFAULT_COMMANDS_SET
commands_set = DEFAULT_COMMANDS_SET
if self.has_config(CONF_COMMANDS_SET):
command_set = self._config[CONF_COMMANDS_SET]
self._open_cmd = command_set.split("_")[0]
self._close_cmd = command_set.split("_")[1]
self._stop_cmd = command_set.split("_")[2]
commands_set = self._config[CONF_COMMANDS_SET]
self._open_cmd = commands_set.split("_")[0]
self._close_cmd = commands_set.split("_")[1]
self._stop_cmd = commands_set.split("_")[2]
print("Initialized cover [{}]".format(self.name))

@property
Expand Down Expand Up @@ -108,13 +110,15 @@ def is_open(self):
"""Return if the cover is open or not."""
if self._config[CONF_POSITIONING_MODE] != COVER_MODE_POSITION:
return None

return self._current_cover_position == 100

@property
def is_closed(self):
"""Return if the cover is closed or not."""
if self._config[CONF_POSITIONING_MODE] != COVER_MODE_POSITION:
return None

return self._current_cover_position == 0

async def async_set_cover_position(self, **kwargs):
Expand All @@ -139,6 +143,9 @@ async def async_set_cover_position(self, **kwargs):

elif self._config[CONF_POSITIONING_MODE] == COVER_MODE_POSITION:
converted_position = int(kwargs[ATTR_POSITION])
if self._config[CONF_POSITION_INVERTED]:
converted_position = 100 - converted_position

if 0 <= converted_position <= 100 and self.has_config(CONF_SET_POSITION_DP):
await self._device.set_dp(
converted_position, self._config[CONF_SET_POSITION_DP]
Expand All @@ -162,10 +169,17 @@ async def async_stop_cover(self, **kwargs):
def status_updated(self):
"""Device status was updated."""
self._state = self.dps(self._dp_id)
if self._state.isupper():
self._open_cmd = self._open_cmd.upper()
self._close_cmd = self._close_cmd.upper()
self._stop_cmd = self._stop_cmd.upper()

if self.has_config(CONF_CURRENT_POSITION_DP):
self._current_cover_position = self.dps(
self._config[CONF_CURRENT_POSITION_DP]
)
curr_pos = self.dps_conf(CONF_CURRENT_POSITION_DP)
if self._config[CONF_POSITION_INVERTED]:
self._current_cover_position = 100 - curr_pos
else:
self._current_cover_position = curr_pos
else:
self._current_cover_position = 50

Expand Down
2 changes: 2 additions & 0 deletions custom_components/localtuya/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"positioning_mode": "Positioning mode",
"current_position_dp": "Current Position (when Position mode is *position*)",
"set_position_dp": "Set Position (when Position Mode is *position*)",
"position_inverted": "Invert 0-100 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",
Expand Down Expand Up @@ -103,6 +104,7 @@
"positioning_mode": "Positioning mode",
"current_position_dp": "Current Position (for *position* mode only)",
"set_position_dp": "Set Position (for *position* mode only)",
"position_inverted": "Invert 0-100 position (when Position Mode is *position*)",
"span_time": "Full opening time, in secs. (for *fake* mode only)",
"unit_of_measurement": "Unit of Measurement",
"device_class": "Device Class",
Expand Down
2 changes: 0 additions & 2 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

![logo](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/logo-small.png)

# localtuya-homeassistant

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).

Expand Down

0 comments on commit 098125f

Please sign in to comment.