diff --git a/custom_components/shelly/configuration_schema.py b/custom_components/shelly/configuration_schema.py index 52aa974..cf45907 100644 --- a/custom_components/shelly/configuration_schema.py +++ b/custom_components/shelly/configuration_schema.py @@ -37,6 +37,7 @@ DEVICE_SCHEMA = vol.Schema({ vol.Required(CONF_ID): cv.string, + vol.Optional(CONF_MOMENTARY_BUTTON, default=False): cv.boolean, vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_LIGHT_SWITCH, default=False): cv.boolean, vol.Optional(CONF_SENSORS): diff --git a/custom_components/shelly/const.py b/custom_components/shelly/const.py index 635f347..7ab0e95 100644 --- a/custom_components/shelly/const.py +++ b/custom_components/shelly/const.py @@ -26,6 +26,7 @@ CONF_IGMPFIX = 'igmp_fix' CONF_MDNS = 'mdns' CONF_LIGHT_SWITCH = 'light_switch' +CONF_MOMENTARY_BUTTON = "momentary_button" CONF_OBJECT_ID_PREFIX = 'id_prefix' CONF_ENTITY_ID = 'entity_id' CONF_SHOW_ID_IN_NAME = 'show_id_in_name' diff --git a/custom_components/shelly/device.py b/custom_components/shelly/device.py index 62da6ea..cce1679 100644 --- a/custom_components/shelly/device.py +++ b/custom_components/shelly/device.py @@ -9,7 +9,7 @@ from homeassistant.util import slugify from homeassistant.const import CONF_NAME -from .const import (CONF_OBJECT_ID_PREFIX, CONF_ENTITY_ID, CONF_SHOW_ID_IN_NAME, +from .const import (CONF_OBJECT_ID_PREFIX, CONF_ENTITY_ID, CONF_MOMENTARY_BUTTON, CONF_SHOW_ID_IN_NAME, ALL_SENSORS, SENSOR_TYPES_CFG, DOMAIN) class ShellyDevice(RestoreEntity): @@ -47,12 +47,25 @@ def __init__(self, dev, instance): self._settings = instance.get_settings(dev.id, dev.block.id) + if hasattr(self._dev, 'kg_momentary_button'): + self._dev.kg_momentary_button = instance._get_specific_config(CONF_MOMENTARY_BUTTON, None, dev.id, dev.block.id) + def _update_ha_state(self): self.schedule_update_ha_state(True) def _updated(self, _block): """Receive events when the switch state changed (by mobile, switch etc)""" + + if hasattr(self._dev, 'kg_send_event_click_count'): + if self._dev.kg_send_event_click_count != 0 or self._dev.kg_send_event_events != "": + self.hass.bus.fire('shelly_click', \ + {'entity_id' : self.entity_id, + 'click_count' : self._dev.kg_send_event_click_count, + 'click_events' : self._dev.kg_send_event_events}) + self._dev.kg_send_event_click_count = 0 + self._dev.kg_send_event_events = "" + disabled = self.registry_entry and self.registry_entry.disabled_by if self.entity_id is not None and not self._is_removed and not disabled: self._update_ha_state() diff --git a/custom_components/shelly/light.py b/custom_components/shelly/light.py index b570b17..822df6c 100755 --- a/custom_components/shelly/light.py +++ b/custom_components/shelly/light.py @@ -117,9 +117,10 @@ def __init__(self, dev, instance): self._color_temp_min = None self._color_temp_max = None self._master_unit = True + self._dim_up_down = 1 self.update() - self._features = SUPPORT_BRIGHTNESS + self._features = SUPPORT_BRIGHTNESS | SUPPORT_EFFECT if getattr(dev, "support_color_temp", False): self._color_temp_min = dev._color_temp_min self._color_temp_max = dev._color_temp_max @@ -137,6 +138,22 @@ def is_on(self): def turn_on(self, **kwargs): brightness = None color_temp = None + + if ATTR_EFFECT in kwargs: + dimtype = kwargs[ATTR_EFFECT] + if dimtype in ["dim_up_down", "dim_up", "dim_down", "dim_stop"]: + if dimtype == "dim_up_down": + if self._dim_up_down == 1: + dimtype = "dim_up" + self._dim_up_down = 0 + else: + dimtype = "dim_down" + self._dim_up_down = 1 + + self._dev.dimming(dimtype, self._state) + + return + if ATTR_BRIGHTNESS in kwargs: brightness = int(kwargs[ATTR_BRIGHTNESS] / 2.55) self._brightness = brightness