mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Remove Logentries (#174939)
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
"""Support for sending data to Logentries webhook endpoint."""
|
||||
|
||||
import json
|
||||
import logging
|
||||
|
||||
import requests
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import CONF_TOKEN, EVENT_STATE_CHANGED
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv, state as state_helper
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = "logentries"
|
||||
|
||||
DEFAULT_HOST = "https://webhook.logentries.com/noformat/logs/"
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{DOMAIN: vol.Schema({vol.Required(CONF_TOKEN): cv.string})}, extra=vol.ALLOW_EXTRA
|
||||
)
|
||||
|
||||
|
||||
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Logentries component."""
|
||||
conf = config[DOMAIN]
|
||||
token = conf.get(CONF_TOKEN)
|
||||
le_wh = f"{DEFAULT_HOST}{token}"
|
||||
|
||||
def logentries_event_listener(event):
|
||||
"""Listen for new messages on the bus and sends them to Logentries."""
|
||||
if (state := event.data.get("new_state")) is None:
|
||||
return
|
||||
try:
|
||||
_state = state_helper.state_as_number(state)
|
||||
except ValueError:
|
||||
_state = state.state
|
||||
json_body = [
|
||||
{
|
||||
"domain": state.domain,
|
||||
"entity_id": state.object_id,
|
||||
"attributes": dict(state.attributes),
|
||||
"time": str(event.time_fired),
|
||||
"value": _state,
|
||||
}
|
||||
]
|
||||
try:
|
||||
payload = {"host": le_wh, "event": json_body}
|
||||
requests.post(le_wh, data=json.dumps(payload), timeout=10)
|
||||
except requests.exceptions.RequestException:
|
||||
_LOGGER.exception("Error sending to Logentries")
|
||||
|
||||
hass.bus.listen(EVENT_STATE_CHANGED, logentries_event_listener)
|
||||
|
||||
return True
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"domain": "logentries",
|
||||
"name": "Logentries",
|
||||
"codeowners": [],
|
||||
"documentation": "https://www.home-assistant.io/integrations/logentries",
|
||||
"iot_class": "cloud_push",
|
||||
"quality_scale": "legacy"
|
||||
}
|
||||
@@ -3935,12 +3935,6 @@
|
||||
"config_flow": true,
|
||||
"iot_class": "local_push"
|
||||
},
|
||||
"logentries": {
|
||||
"name": "Logentries",
|
||||
"integration_type": "hub",
|
||||
"config_flow": false,
|
||||
"iot_class": "cloud_push"
|
||||
},
|
||||
"logitech": {
|
||||
"name": "Logitech",
|
||||
"integrations": {
|
||||
|
||||
@@ -546,7 +546,6 @@ INTEGRATIONS_WITHOUT_QUALITY_SCALE_FILE = [
|
||||
"local_todo",
|
||||
"location",
|
||||
"locative",
|
||||
"logentries",
|
||||
"logi_circle",
|
||||
"london_air",
|
||||
"london_underground",
|
||||
@@ -1508,7 +1507,6 @@ INTEGRATIONS_WITHOUT_SCALE = [
|
||||
"local_todo",
|
||||
"location",
|
||||
"locative",
|
||||
"logentries",
|
||||
"logi_circle",
|
||||
"london_air",
|
||||
"london_underground",
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
"""Tests for the logentries component."""
|
||||
@@ -1,75 +0,0 @@
|
||||
"""The tests for the Logentries component."""
|
||||
|
||||
from unittest.mock import ANY, call, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import logentries
|
||||
from homeassistant.const import STATE_OFF, STATE_ON
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
async def test_setup_config_full(hass: HomeAssistant) -> None:
|
||||
"""Test setup with all data."""
|
||||
config = {"logentries": {"token": "secret"}}
|
||||
assert await async_setup_component(hass, logentries.DOMAIN, config)
|
||||
|
||||
with patch("homeassistant.components.logentries.requests.post") as mock_post:
|
||||
hass.states.async_set("fake.entity", STATE_ON)
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_post.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_setup_config_defaults(hass: HomeAssistant) -> None:
|
||||
"""Test setup with defaults."""
|
||||
config = {"logentries": {"token": "token"}}
|
||||
assert await async_setup_component(hass, logentries.DOMAIN, config)
|
||||
|
||||
with patch("homeassistant.components.logentries.requests.post") as mock_post:
|
||||
hass.states.async_set("fake.entity", STATE_ON)
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_post.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_dump():
|
||||
"""Mock json dumps."""
|
||||
with patch("json.dumps") as mock_dump:
|
||||
yield mock_dump
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_requests():
|
||||
"""Mock requests."""
|
||||
with patch.object(logentries, "requests") as mock_requests:
|
||||
yield mock_requests
|
||||
|
||||
|
||||
async def test_event_listener(hass: HomeAssistant, mock_dump, mock_requests) -> None:
|
||||
"""Test event listener."""
|
||||
mock_dump.side_effect = lambda x: x
|
||||
mock_post = mock_requests.post
|
||||
mock_requests.exceptions.RequestException = Exception
|
||||
config = {"logentries": {"token": "token"}}
|
||||
assert await async_setup_component(hass, logentries.DOMAIN, config)
|
||||
|
||||
valid = {"1": 1, "1.0": 1.0, STATE_ON: 1, STATE_OFF: 0, "foo": "foo"}
|
||||
for in_, out in valid.items():
|
||||
payload = {
|
||||
"host": "https://webhook.logentries.com/noformat/logs/token",
|
||||
"event": [
|
||||
{
|
||||
"domain": "fake",
|
||||
"entity_id": "entity",
|
||||
"attributes": {},
|
||||
"time": ANY,
|
||||
"value": out,
|
||||
}
|
||||
],
|
||||
}
|
||||
hass.states.async_set("fake.entity", in_)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_post.call_count == 1
|
||||
assert mock_post.call_args == call(payload["host"], data=payload, timeout=10)
|
||||
mock_post.reset_mock()
|
||||
Reference in New Issue
Block a user