Skip to content
1 change: 1 addition & 0 deletions custom_components/shelly/configuration_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions custom_components/shelly/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
15 changes: 14 additions & 1 deletion custom_components/shelly/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
19 changes: 18 additions & 1 deletion custom_components/shelly/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down