mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix Shelly button first trigger (#49635)
This commit is contained in:
parent
aaba9766ff
commit
34a588d1ba
@ -33,6 +33,7 @@ from .const import (
|
|||||||
POLLING_TIMEOUT_SEC,
|
POLLING_TIMEOUT_SEC,
|
||||||
REST,
|
REST,
|
||||||
REST_SENSORS_UPDATE_INTERVAL,
|
REST_SENSORS_UPDATE_INTERVAL,
|
||||||
|
SHBTN_MODELS,
|
||||||
SLEEP_PERIOD_MULTIPLIER,
|
SLEEP_PERIOD_MULTIPLIER,
|
||||||
UPDATE_PERIOD_MULTIPLIER,
|
UPDATE_PERIOD_MULTIPLIER,
|
||||||
)
|
)
|
||||||
@ -181,6 +182,17 @@ class ShellyDeviceWrapper(update_coordinator.DataUpdateCoordinator):
|
|||||||
if not self.device.initialized:
|
if not self.device.initialized:
|
||||||
return
|
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
|
# Check for input events
|
||||||
for block in self.device.blocks:
|
for block in self.device.blocks:
|
||||||
if (
|
if (
|
||||||
|
@ -49,7 +49,7 @@ BASIC_INPUTS_EVENTS_TYPES = {
|
|||||||
"long",
|
"long",
|
||||||
}
|
}
|
||||||
|
|
||||||
SHBTN_1_INPUTS_EVENTS_TYPES = {
|
SHBTN_INPUTS_EVENTS_TYPES = {
|
||||||
"single",
|
"single",
|
||||||
"double",
|
"double",
|
||||||
"triple",
|
"triple",
|
||||||
@ -72,6 +72,8 @@ INPUTS_EVENTS_SUBTYPES = {
|
|||||||
"button3": 3,
|
"button3": 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHBTN_MODELS = ["SHBTN-1", "SHBTN-2"]
|
||||||
|
|
||||||
# Kelvin value for colorTemp
|
# Kelvin value for colorTemp
|
||||||
KELVIN_MAX_VALUE = 6500
|
KELVIN_MAX_VALUE = 6500
|
||||||
KELVIN_MIN_VALUE_WHITE = 2700
|
KELVIN_MIN_VALUE_WHITE = 2700
|
||||||
|
@ -27,7 +27,8 @@ from .const import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
EVENT_SHELLY_CLICK,
|
EVENT_SHELLY_CLICK,
|
||||||
INPUTS_EVENTS_SUBTYPES,
|
INPUTS_EVENTS_SUBTYPES,
|
||||||
SHBTN_1_INPUTS_EVENTS_TYPES,
|
SHBTN_INPUTS_EVENTS_TYPES,
|
||||||
|
SHBTN_MODELS,
|
||||||
SUPPORTED_INPUTS_EVENTS_TYPES,
|
SUPPORTED_INPUTS_EVENTS_TYPES,
|
||||||
)
|
)
|
||||||
from .utils import get_device_wrapper, get_input_triggers
|
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:
|
if not wrapper:
|
||||||
raise InvalidDeviceAutomationConfig(f"Device not found: {device_id}")
|
raise InvalidDeviceAutomationConfig(f"Device not found: {device_id}")
|
||||||
|
|
||||||
if wrapper.model in ("SHBTN-1", "SHBTN-2"):
|
if wrapper.model in SHBTN_MODELS:
|
||||||
for trigger in SHBTN_1_INPUTS_EVENTS_TYPES:
|
for trigger in SHBTN_INPUTS_EVENTS_TYPES:
|
||||||
triggers.append(
|
triggers.append(
|
||||||
{
|
{
|
||||||
CONF_PLATFORM: "device",
|
CONF_PLATFORM: "device",
|
||||||
|
@ -16,7 +16,8 @@ from .const import (
|
|||||||
COAP,
|
COAP,
|
||||||
DATA_CONFIG_ENTRY,
|
DATA_CONFIG_ENTRY,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SHBTN_1_INPUTS_EVENTS_TYPES,
|
SHBTN_INPUTS_EVENTS_TYPES,
|
||||||
|
SHBTN_MODELS,
|
||||||
SHIX3_1_INPUTS_EVENTS_TYPES,
|
SHIX3_1_INPUTS_EVENTS_TYPES,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -111,7 +112,7 @@ def get_device_channel_name(
|
|||||||
def is_momentary_input(settings: dict, block: aioshelly.Block) -> bool:
|
def is_momentary_input(settings: dict, block: aioshelly.Block) -> bool:
|
||||||
"""Return true if input button settings is set to a momentary type."""
|
"""Return true if input button settings is set to a momentary type."""
|
||||||
# Shelly Button type is fixed to momentary and no btn_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
|
return True
|
||||||
|
|
||||||
button = settings.get("relays") or settings.get("lights") or settings.get("inputs")
|
button = settings.get("relays") or settings.get("lights") or settings.get("inputs")
|
||||||
@ -158,8 +159,8 @@ def get_input_triggers(
|
|||||||
else:
|
else:
|
||||||
subtype = f"button{int(block.channel)+1}"
|
subtype = f"button{int(block.channel)+1}"
|
||||||
|
|
||||||
if device.settings["device"]["type"] in ("SHBTN-1", "SHBTN-2"):
|
if device.settings["device"]["type"] in SHBTN_MODELS:
|
||||||
trigger_types = SHBTN_1_INPUTS_EVENTS_TYPES
|
trigger_types = SHBTN_INPUTS_EVENTS_TYPES
|
||||||
elif device.settings["device"]["type"] == "SHIX3-1":
|
elif device.settings["device"]["type"] == "SHIX3-1":
|
||||||
trigger_types = SHIX3_1_INPUTS_EVENTS_TYPES
|
trigger_types = SHIX3_1_INPUTS_EVENTS_TYPES
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user