* Add logbook and device trigger platforms to Shelly Add `logbook` platform for describing “shelly.click” event Add `device_trigger` platform for adding automation based on click events: Example of logbook event: Shelly 'single' click event for Test I3 channel 3 was fired. (Test I3 is the name of the device) Example of automation triggers: First button triple clicked First button long clicked and then single clicked First button double clicked First button long clicked First button single clicked and then long clicked First button single clicked Second button triple clicked .. Second button single clicked * Fix codespell * Remove pylint added for debug * Add tests * Rebase * Fix Rebase & Apply PR review suggestions Fix tests after rebasing Use `INPUTS_EVENTS_DICT` for input triggers Apply PR suggestions
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
"""The tests for Shelly logbook."""
|
|
from homeassistant.components import logbook
|
|
from homeassistant.components.shelly.const import (
|
|
ATTR_CHANNEL,
|
|
ATTR_CLICK_TYPE,
|
|
ATTR_DEVICE,
|
|
DOMAIN,
|
|
EVENT_SHELLY_CLICK,
|
|
)
|
|
from homeassistant.const import ATTR_DEVICE_ID
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
from tests.components.logbook.test_init import MockLazyEventPartialState
|
|
|
|
|
|
async def test_humanify_shelly_click_event(hass, coap_wrapper):
|
|
"""Test humanifying Shelly click event."""
|
|
assert coap_wrapper
|
|
hass.config.components.add("recorder")
|
|
assert await async_setup_component(hass, "logbook", {})
|
|
entity_attr_cache = logbook.EntityAttributeCache(hass)
|
|
|
|
event1, event2 = list(
|
|
logbook.humanify(
|
|
hass,
|
|
[
|
|
MockLazyEventPartialState(
|
|
EVENT_SHELLY_CLICK,
|
|
{
|
|
ATTR_DEVICE_ID: coap_wrapper.device_id,
|
|
ATTR_DEVICE: "shellyix3-12345678",
|
|
ATTR_CLICK_TYPE: "single",
|
|
ATTR_CHANNEL: 1,
|
|
},
|
|
),
|
|
MockLazyEventPartialState(
|
|
EVENT_SHELLY_CLICK,
|
|
{
|
|
ATTR_DEVICE_ID: "no_device_id",
|
|
ATTR_DEVICE: "shellyswitch25-12345678",
|
|
ATTR_CLICK_TYPE: "long",
|
|
ATTR_CHANNEL: 2,
|
|
},
|
|
),
|
|
],
|
|
entity_attr_cache,
|
|
{},
|
|
)
|
|
)
|
|
|
|
assert event1["name"] == "Shelly"
|
|
assert event1["domain"] == DOMAIN
|
|
assert (
|
|
event1["message"] == "'single' click event for Test name channel 1 was fired."
|
|
)
|
|
|
|
assert event2["name"] == "Shelly"
|
|
assert event2["domain"] == DOMAIN
|
|
assert (
|
|
event2["message"]
|
|
== "'long' click event for shellyswitch25-12345678 channel 2 was fired."
|
|
)
|