Fix Shelly button first trigger (#49635)
parent
aaba9766ff
commit
34a588d1ba
|
@ -33,6 +33,7 @@ from .const import (
|
|||
POLLING_TIMEOUT_SEC,
|
||||
REST,
|
||||
REST_SENSORS_UPDATE_INTERVAL,
|
||||
SHBTN_MODELS,
|
||||
SLEEP_PERIOD_MULTIPLIER,
|
||||
UPDATE_PERIOD_MULTIPLIER,
|
||||
)
|
||||
|
@ -181,6 +182,17 @@ class ShellyDeviceWrapper(update_coordinator.DataUpdateCoordinator):
|
|||
if not self.device.initialized:
|
||||
return
|
||||
|
||||
# For buttons which are battery powered - set initial value for last_event_count
|
||||
if self.model in SHBTN_MODELS and self._last_input_events_count.get(1) is None:
|
||||
for block in self.device.blocks:
|
||||
if block.type != "device":
|
||||
continue
|
||||
|
||||
if block.wakeupEvent[0] == "button":
|
||||
self._last_input_events_count[1] = -1
|
||||
|
||||
break
|
||||
|
||||
# Check for input events
|
||||
for block in self.device.blocks:
|
||||
if (
|
||||
|
|
|
@ -49,7 +49,7 @@ BASIC_INPUTS_EVENTS_TYPES = {
|
|||
"long",
|
||||
}
|
||||
|
||||
SHBTN_1_INPUTS_EVENTS_TYPES = {
|
||||
SHBTN_INPUTS_EVENTS_TYPES = {
|
||||
"single",
|
||||
"double",
|
||||
"triple",
|
||||
|
@ -72,6 +72,8 @@ INPUTS_EVENTS_SUBTYPES = {
|
|||
"button3": 3,
|
||||
}
|
||||
|
||||
SHBTN_MODELS = ["SHBTN-1", "SHBTN-2"]
|
||||
|
||||
# Kelvin value for colorTemp
|
||||
KELVIN_MAX_VALUE = 6500
|
||||
KELVIN_MIN_VALUE_WHITE = 2700
|
||||
|
|
|
@ -27,7 +27,8 @@ from .const import (
|
|||
DOMAIN,
|
||||
EVENT_SHELLY_CLICK,
|
||||
INPUTS_EVENTS_SUBTYPES,
|
||||
SHBTN_1_INPUTS_EVENTS_TYPES,
|
||||
SHBTN_INPUTS_EVENTS_TYPES,
|
||||
SHBTN_MODELS,
|
||||
SUPPORTED_INPUTS_EVENTS_TYPES,
|
||||
)
|
||||
from .utils import get_device_wrapper, get_input_triggers
|
||||
|
@ -69,8 +70,8 @@ async def async_get_triggers(hass: HomeAssistant, device_id: str) -> list[dict]:
|
|||
if not wrapper:
|
||||
raise InvalidDeviceAutomationConfig(f"Device not found: {device_id}")
|
||||
|
||||
if wrapper.model in ("SHBTN-1", "SHBTN-2"):
|
||||
for trigger in SHBTN_1_INPUTS_EVENTS_TYPES:
|
||||
if wrapper.model in SHBTN_MODELS:
|
||||
for trigger in SHBTN_INPUTS_EVENTS_TYPES:
|
||||
triggers.append(
|
||||
{
|
||||
CONF_PLATFORM: "device",
|
||||
|
|
|
@ -16,7 +16,8 @@ from .const import (
|
|||
COAP,
|
||||
DATA_CONFIG_ENTRY,
|
||||
DOMAIN,
|
||||
SHBTN_1_INPUTS_EVENTS_TYPES,
|
||||
SHBTN_INPUTS_EVENTS_TYPES,
|
||||
SHBTN_MODELS,
|
||||
SHIX3_1_INPUTS_EVENTS_TYPES,
|
||||
)
|
||||
|
||||
|
@ -111,7 +112,7 @@ def get_device_channel_name(
|
|||
def is_momentary_input(settings: dict, block: aioshelly.Block) -> bool:
|
||||
"""Return true if input button settings is set to a momentary type."""
|
||||
# Shelly Button type is fixed to momentary and no btn_type
|
||||
if settings["device"]["type"] in ("SHBTN-1", "SHBTN-2"):
|
||||
if settings["device"]["type"] in SHBTN_MODELS:
|
||||
return True
|
||||
|
||||
button = settings.get("relays") or settings.get("lights") or settings.get("inputs")
|
||||
|
@ -158,8 +159,8 @@ def get_input_triggers(
|
|||
else:
|
||||
subtype = f"button{int(block.channel)+1}"
|
||||
|
||||
if device.settings["device"]["type"] in ("SHBTN-1", "SHBTN-2"):
|
||||
trigger_types = SHBTN_1_INPUTS_EVENTS_TYPES
|
||||
if device.settings["device"]["type"] in SHBTN_MODELS:
|
||||
trigger_types = SHBTN_INPUTS_EVENTS_TYPES
|
||||
elif device.settings["device"]["type"] == "SHIX3-1":
|
||||
trigger_types = SHIX3_1_INPUTS_EVENTS_TYPES
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue