Compare commits

...

21 Commits

Author SHA1 Message Date
Paulus Schoutsen
dfc345a921 Merge pull request #36840 from home-assistant/rc 2020-06-15 17:32:52 -07:00
Paulus Schoutsen
0127974f09 Bumped version to 0.111.3 2020-06-15 16:35:41 -07:00
Paulus Schoutsen
108082fd07 Fix cloudhooks coming in for non existing webhooks (#36836)
* Fix cloudhooks coming in for non existing webhooks

* Fix tests"
2020-06-15 16:35:32 -07:00
kennedyshead
61d6bd0cb5 Bump aioasuswrt to 1.2.6 (#36820)
Co-authored-by: magnusknutas <magnus@thefarm.se>
2020-06-15 16:35:32 -07:00
Paulus Schoutsen
3a2138131c Fire config changed event during start (#36812) 2020-06-15 16:35:31 -07:00
Tom Harris
ec65ebacd3 Fix X10 devices and adding default links (#36807) 2020-06-15 16:35:30 -07:00
David F. Mulcahey
b45e49902c Bump ZHA quirks (#36797) 2020-06-15 16:35:29 -07:00
N1c093
12781bf842 Fix nanoleaf attribute when running an effect (#36794) 2020-06-15 16:35:28 -07:00
J. Nick Koston
d0ca8e62a4 Fix history graphs with mysql/mariadb (#36769) 2020-06-15 16:35:27 -07:00
Franck Nijhof
c37cd835b9 Upgrade wled 0.4.3 (#36760) 2020-06-15 16:35:27 -07:00
Franck Nijhof
e5f08ee657 Merge pull request #36756 from home-assistant/rc 2020-06-13 15:01:30 +02:00
Bram Kragten
12c649ba27 Bumped version to 0.111.2 2020-06-13 12:49:19 +02:00
Bram Kragten
5eb7f5fcf3 Update frontend to 20200603.3 (#36751) 2020-06-13 12:48:19 +02:00
J. Nick Koston
48b6f41048 Fix history timezone with postgres and other dbs (#36746) 2020-06-13 12:48:18 +02:00
Robert Svensson
16d045aa9f Make Axis non-privileged users work again (#36731) 2020-06-13 12:48:18 +02:00
Franck Nijhof
66ad69bff3 Fix logbook filtering for described events (#36727) 2020-06-13 12:46:57 +02:00
Fredrik Erlandsson
599288dae2 Fix Daikin discovery (#36704) 2020-06-13 12:37:44 +02:00
Alexei Chetroi
2594f11b34 Fix ZHA Metering channel formatting method (#36697)
Since zigpy change to support bitmap classes, formatting string was incorrectly generated for the newly joined devices with SmartEnergy metering clusters.
2020-06-13 12:37:44 +02:00
jjlawren
ad7edb4abe Fix missing options in Plex config entry (#36683) 2020-06-13 12:37:43 +02:00
Paulus Schoutsen
9e73853d65 Guard OwnTracks writing state before hass available (#36680) 2020-06-13 12:37:42 +02:00
zewelor
504cb26329 Fix nightlight support detection (#36656) 2020-06-13 12:37:41 +02:00
37 changed files with 337 additions and 71 deletions

View File

@@ -2,6 +2,6 @@
"domain": "asuswrt",
"name": "ASUSWRT",
"documentation": "https://www.home-assistant.io/integrations/asuswrt",
"requirements": ["aioasuswrt==1.2.5"],
"requirements": ["aioasuswrt==1.2.6"],
"codeowners": ["@kennedyshead"]
}

View File

@@ -5,6 +5,7 @@ import asyncio
import async_timeout
import axis
from axis.configuration import Configuration
from axis.errors import Unauthorized
from axis.event_stream import OPERATION_INITIALIZED
from axis.mqtt import mqtt_json_to_event
from axis.streammanager import SIGNAL_PLAYING, STATE_STOPPED
@@ -160,9 +161,13 @@ class AxisNetworkDevice:
async def use_mqtt(self, hass: HomeAssistant, component: str) -> None:
"""Set up to use MQTT."""
status = await hass.async_add_executor_job(
self.api.vapix.mqtt.get_client_status
)
try:
status = await hass.async_add_executor_job(
self.api.vapix.mqtt.get_client_status
)
except Unauthorized:
# This means the user has too low privileges
status = {}
if status.get("data", {}).get("status", {}).get("state") == "active":
self.listeners.append(

View File

@@ -3,7 +3,7 @@
"name": "Axis",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/axis",
"requirements": ["axis==29"],
"requirements": ["axis==30"],
"zeroconf": ["_axis-video._tcp.local."],
"after_dependencies": ["mqtt"],
"codeowners": ["@Kane610"]

View File

@@ -19,7 +19,7 @@ from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util.aiohttp import MockRequest
from . import alexa_config, google_config, utils
from .const import DISPATCHER_REMOTE_UPDATE
from .const import DISPATCHER_REMOTE_UPDATE, DOMAIN
from .prefs import CloudPreferences
_LOGGER = logging.getLogger(__name__)
@@ -182,6 +182,7 @@ class CloudClient(Interface):
headers=payload["headers"],
method=payload["method"],
query_string=payload["query"],
mock_source=DOMAIN,
)
response = await self._hass.components.webhook.async_handle_webhook(

View File

@@ -72,6 +72,8 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
# For backwards compat, set unique ID
if entry.unique_id is None:
hass.config_entries.async_update_entry(entry, unique_id=conf[KEY_MAC])
elif ".local" in entry.unique_id:
hass.config_entries.async_update_entry(entry, unique_id=conf[KEY_MAC])
daikin_api = await daikin_api_setup(
hass,
conf[CONF_HOST],

View File

@@ -6,12 +6,13 @@ from uuid import uuid4
from aiohttp import ClientError, web_exceptions
from async_timeout import timeout
from pydaikin.daikin_base import Appliance
from pydaikin.discovery import Discovery
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import CONF_HOST, CONF_PASSWORD
from .const import CONF_KEY, CONF_UUID, KEY_HOSTNAME, KEY_IP, KEY_MAC, TIMEOUT
from .const import CONF_KEY, CONF_UUID, KEY_IP, KEY_MAC, TIMEOUT
_LOGGER = logging.getLogger(__name__)
@@ -128,7 +129,8 @@ class FlowHandler(config_entries.ConfigFlow):
async def async_step_zeroconf(self, discovery_info):
"""Prepare configuration for a discovered Daikin device."""
_LOGGER.debug("Zeroconf discovery_info: %s", discovery_info)
await self.async_set_unique_id(discovery_info[KEY_HOSTNAME])
devices = Discovery.poll(discovery_info[CONF_HOST])
await self.async_set_unique_id(next(iter(devices.values()))[KEY_MAC])
self._abort_if_unique_id_configured()
self.host = discovery_info[CONF_HOST]
return await self.async_step_user()

View File

@@ -64,6 +64,5 @@ CONF_UUID = "uuid"
KEY_MAC = "mac"
KEY_IP = "ip"
KEY_HOSTNAME = "hostname"
TIMEOUT = 60

View File

@@ -3,7 +3,7 @@
"name": "Daikin AC",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/daikin",
"requirements": ["pydaikin==2.1.1"],
"requirements": ["pydaikin==2.1.2"],
"codeowners": ["@fredrike"],
"zeroconf": ["_dkapi._tcp.local."],
"quality_scale": "platinum"

View File

@@ -2,7 +2,7 @@
"domain": "frontend",
"name": "Home Assistant Frontend",
"documentation": "https://www.home-assistant.io/integrations/frontend",
"requirements": ["home-assistant-frontend==20200603.2"],
"requirements": ["home-assistant-frontend==20200603.3"],
"dependencies": [
"api",
"auth",

View File

@@ -249,9 +249,19 @@ async def async_setup(hass, config):
await hassio.update_hass_api(config.get("http", {}), refresh_token)
last_timezone = None
async def push_config(_):
"""Push core config to Hass.io."""
await hassio.update_hass_timezone(str(hass.config.time_zone))
nonlocal last_timezone
new_timezone = str(hass.config.time_zone)
if new_timezone == last_timezone:
return
last_timezone = new_timezone
await hassio.update_hass_timezone(new_timezone)
hass.bus.async_listen(EVENT_CORE_CONFIG_UPDATE, push_config)

View File

@@ -12,7 +12,7 @@ import voluptuous as vol
from homeassistant.components import recorder
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.recorder.models import DB_TIMEZONE, States
from homeassistant.components.recorder.models import States, process_timestamp
from homeassistant.components.recorder.util import execute, session_scope
from homeassistant.const import (
ATTR_HIDDEN,
@@ -304,6 +304,10 @@ def _sorted_states_to_json(
elapsed = time.perf_counter() - timer_start
_LOGGER.debug("getting %d first datapoints took %fs", len(result), elapsed)
# Called in a tight loop so cache the function
# here
_process_timestamp = process_timestamp
# Append all changes to it
for ent_id, group in groupby(states, lambda state: state.entity_id):
domain = split_entity_id(ent_id)[0]
@@ -347,7 +351,9 @@ def _sorted_states_to_json(
ent_results.append(
{
STATE_KEY: db_state.state,
LAST_CHANGED_KEY: f"{str(db_state.last_changed).replace(' ','T').split('.')[0]}{DB_TIMEZONE}",
LAST_CHANGED_KEY: _process_timestamp(
db_state.last_changed
).isoformat(),
}
)
prev_state = db_state

View File

@@ -124,4 +124,4 @@ class InsteonEntity(Entity):
async def _async_add_default_links(self):
"""Add default links between the device and the modem."""
await self._insteon_device.async_add_default_links(self.address)
await self._insteon_device.async_add_default_links()

View File

@@ -2,6 +2,6 @@
"domain": "insteon",
"name": "Insteon",
"documentation": "https://www.home-assistant.io/integrations/insteon",
"requirements": ["pyinsteon==1.0.3"],
"requirements": ["pyinsteon==1.0.4"],
"codeowners": ["@teharris1"]
}

View File

@@ -331,7 +331,7 @@ def _get_related_entity_ids(session, entity_filter):
query = session.query(States).with_entities(States.entity_id).distinct()
for tryno in range(0, RETRIES):
for tryno in range(RETRIES):
try:
result = [row.entity_id for row in query if entity_filter(row.entity_id)]
@@ -410,11 +410,12 @@ def _get_events(hass, config, start_day, end_day, entity_id=None):
def _keep_event(hass, event, entities_filter):
domain, entity_id = None, None
domain = event.data.get(ATTR_DOMAIN)
entity_id = event.data.get("entity_id")
if entity_id:
domain = split_entity_id(entity_id)[0]
if event.event_type == EVENT_STATE_CHANGED:
entity_id = event.data.get("entity_id")
if entity_id is None:
return False
@@ -432,7 +433,6 @@ def _keep_event(hass, event, entities_filter):
if new_state.get("state") == old_state.get("state"):
return False
domain = split_entity_id(entity_id)[0]
attributes = new_state.get("attributes", {})
# Also filter auto groups.
@@ -446,13 +446,13 @@ def _keep_event(hass, event, entities_filter):
elif event.event_type == EVENT_LOGBOOK_ENTRY:
domain = event.data.get(ATTR_DOMAIN)
entity_id = event.data.get(ATTR_ENTITY_ID)
elif event.event_type == EVENT_SCRIPT_STARTED:
domain = "script"
entity_id = event.data.get(ATTR_ENTITY_ID)
elif event.event_type in hass.data.get(DOMAIN, {}):
elif not entity_id and event.event_type in hass.data.get(DOMAIN, {}):
# If the entity_id isn't described, use the domain that describes
# the event for filtering.
domain = hass.data[DOMAIN][event.event_type][0]
if not entity_id and domain:

View File

@@ -230,7 +230,6 @@ class NanoleafLight(LightEntity):
try:
self._available = self._light.available
self._brightness = self._light.brightness
self._color_temp = self._light.color_temperature
self._effects_list = self._light.effects
# Nanoleaf api returns non-existent effect named "*Solid*" when light set to solid color.
# This causes various issues with scening (see https://github.com/home-assistant/core/issues/36359).
@@ -238,7 +237,12 @@ class NanoleafLight(LightEntity):
self._effect = (
self._light.effect if self._light.effect in self._effects_list else None
)
self._hs_color = self._light.hue, self._light.saturation
if self._effect is None:
self._color_temp = self._light.color_temperature
self._hs_color = self._light.hue, self._light.saturation
else:
self._color_temp = None
self._hs_color = None
self._state = self._light.on
except Unavailable as err:
_LOGGER.error("Could not update status for %s (%s)", self.name, err)

View File

@@ -154,4 +154,5 @@ class OwnTracksEntity(TrackerEntity, RestoreEntity):
def update_data(self, data):
"""Mark the device as seen."""
self._data = data
self.async_write_ha_state()
if self.hass:
self.async_write_ha_state()

View File

@@ -9,6 +9,7 @@ from plexwebsocket import PlexWebsocket
import requests.exceptions
import voluptuous as vol
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
from homeassistant.components.media_player.const import (
ATTR_MEDIA_CONTENT_ID,
ATTR_MEDIA_CONTENT_TYPE,
@@ -65,6 +66,11 @@ async def async_setup_entry(hass, entry):
entry, unique_id=entry.data[CONF_SERVER_IDENTIFIER]
)
if MP_DOMAIN not in entry.options:
options = dict(entry.options)
options.setdefault(MP_DOMAIN, {})
hass.config_entries.async_update_entry(entry, options=options)
plex_server = PlexServer(
hass, server_config, entry.data[CONF_SERVER_IDENTIFIER], entry.options
)

View File

@@ -12,6 +12,7 @@ from homeassistant.const import HTTP_OK
from homeassistant.core import callback
from homeassistant.helpers.network import get_url
from homeassistant.loader import bind_hass
from homeassistant.util.aiohttp import MockRequest
_LOGGER = logging.getLogger(__name__)
@@ -76,9 +77,15 @@ async def async_handle_webhook(hass, webhook_id, request):
# Always respond successfully to not give away if a hook exists or not.
if webhook is None:
peer_ip = request[KEY_REAL_IP]
if isinstance(request, MockRequest):
received_from = request.mock_source
else:
received_from = request[KEY_REAL_IP]
_LOGGER.warning(
"Received message for unregistered webhook %s from %s", webhook_id, peer_ip
"Received message for unregistered webhook %s from %s",
webhook_id,
received_from,
)
# Look at content to provide some context for received webhook
# Limit to 64 chars to avoid flooding the log

View File

@@ -3,7 +3,7 @@
"name": "WLED",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/wled",
"requirements": ["wled==0.4.2"],
"requirements": ["wled==0.4.3"],
"zeroconf": ["_wled._tcp.local."],
"codeowners": ["@frenck"],
"quality_scale": "platinum"

View File

@@ -239,11 +239,12 @@ class YeelightDevice:
@property
def is_nightlight_supported(self) -> bool:
"""Return true / false if nightlight is supported."""
if self.model:
return self.bulb.get_model_specs().get("night_light", False)
"""
Return true / false if nightlight is supported.
Uses brightness as it appears to be supported in both ceiling and other lights.
"""
# It should support both ceiling and other lights
return self._nightlight_brightness is not None
@property
@@ -333,6 +334,12 @@ class YeelightDevice:
"""Request device capabilities."""
try:
self.bulb.get_capabilities()
_LOGGER.debug(
"Device %s, %s capabilities: %s",
self.ipaddr,
self.name,
self.bulb.capabilities,
)
except BulbException as ex:
_LOGGER.error(
"Unable to get device capabilities %s, %s: %s",

View File

@@ -128,7 +128,7 @@ class Metering(ZigbeeChannel):
"demand_formatting", 0xF9
) # 1 digit to the right, 15 digits to the left
r_digits = fmting & 0x07 # digits to the right of decimal point
r_digits = int(fmting & 0x07) # digits to the right of decimal point
l_digits = (fmting >> 3) & 0x0F # digits to the left of decimal point
if l_digits == 0:
l_digits = 15

View File

@@ -6,7 +6,7 @@
"requirements": [
"bellows==0.16.2",
"pyserial==3.4",
"zha-quirks==0.0.39",
"zha-quirks==0.0.40",
"zigpy-cc==0.4.4",
"zigpy-deconz==0.9.2",
"zigpy==0.20.4",

View File

@@ -1,7 +1,7 @@
"""Constants used by Home Assistant components."""
MAJOR_VERSION = 0
MINOR_VERSION = 111
PATCH_VERSION = "1"
PATCH_VERSION = "3"
__short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}"
__version__ = f"{__short_version__}.{PATCH_VERSION}"
REQUIRED_PYTHON_VER = (3, 7, 0)

View File

@@ -261,11 +261,11 @@ class HomeAssistant:
This method is a coroutine.
"""
_LOGGER.info("Starting Home Assistant")
self.state = CoreState.starting
setattr(self.loop, "_thread_ident", threading.get_ident())
self.bus.async_fire(EVENT_HOMEASSISTANT_START)
self.state = CoreState.starting
self.bus.async_fire(EVENT_CORE_CONFIG_UPDATE)
self.bus.async_fire(EVENT_HOMEASSISTANT_START)
try:
# Only block for EVENT_HOMEASSISTANT_START listener
@@ -291,8 +291,9 @@ class HomeAssistant:
return
self.state = CoreState.running
_async_create_timer(self)
self.bus.async_fire(EVENT_CORE_CONFIG_UPDATE)
self.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
_async_create_timer(self)
def add_job(self, target: Callable[..., Any], *args: Any) -> None:
"""Add job to the executor pool.

View File

@@ -12,7 +12,7 @@ cryptography==2.9.2
defusedxml==0.6.0
distro==1.5.0
hass-nabucasa==0.34.6
home-assistant-frontend==20200603.2
home-assistant-frontend==20200603.3
importlib-metadata==1.6.0
jinja2>=2.11.1
netdisco==2.7.0

View File

@@ -1,4 +1,5 @@
"""Utilities to help with aiohttp."""
import io
import json
from typing import Any, Dict, Optional
from urllib.parse import parse_qsl
@@ -8,12 +9,29 @@ from multidict import CIMultiDict, MultiDict
from homeassistant.const import HTTP_OK
class MockStreamReader:
"""Small mock to imitate stream reader."""
def __init__(self, content: bytes) -> None:
"""Initialize mock stream reader."""
self._content = io.BytesIO(content)
async def read(self, byte_count: int = -1) -> bytes:
"""Read bytes."""
if byte_count == -1:
return self._content.read()
return self._content.read(byte_count)
class MockRequest:
"""Mock an aiohttp request."""
mock_source: Optional[str] = None
def __init__(
self,
content: bytes,
mock_source: str,
method: str = "GET",
status: int = HTTP_OK,
headers: Optional[Dict[str, str]] = None,
@@ -27,6 +45,7 @@ class MockRequest:
self.headers: CIMultiDict[str] = CIMultiDict(headers or {})
self.query_string = query_string or ""
self._content = content
self.mock_source = mock_source
@property
def query(self) -> "MultiDict[str]":
@@ -38,6 +57,11 @@ class MockRequest:
"""Return the body as text."""
return self._content.decode("utf-8")
@property
def content(self) -> MockStreamReader:
"""Return the body as text."""
return MockStreamReader(self._content)
async def json(self) -> Any:
"""Return the body as JSON."""
return json.loads(self._text)

View File

@@ -156,7 +156,7 @@ aio_georss_gdacs==0.3
aioambient==1.1.1
# homeassistant.components.asuswrt
aioasuswrt==1.2.5
aioasuswrt==1.2.6
# homeassistant.components.aws
aiobotocore==0.11.1
@@ -306,7 +306,7 @@ avea==1.4
avri-api==0.1.7
# homeassistant.components.axis
axis==29
axis==30
# homeassistant.components.azure_event_hub
azure-eventhub==5.1.0
@@ -734,7 +734,7 @@ hole==0.5.1
holidays==0.10.2
# homeassistant.components.frontend
home-assistant-frontend==20200603.2
home-assistant-frontend==20200603.3
# homeassistant.components.zwave
homeassistant-pyozw==0.1.10
@@ -1263,7 +1263,7 @@ pycsspeechtts==1.0.3
# pycups==1.9.73
# homeassistant.components.daikin
pydaikin==2.1.1
pydaikin==2.1.2
# homeassistant.components.danfoss_air
pydanfossair==0.1.0
@@ -1375,7 +1375,7 @@ pyialarm==0.3
pyicloud==0.9.7
# homeassistant.components.insteon
pyinsteon==1.0.3
pyinsteon==1.0.4
# homeassistant.components.intesishome
pyintesishome==1.7.4
@@ -2195,7 +2195,7 @@ wirelesstagpy==0.4.0
withings-api==2.1.3
# homeassistant.components.wled
wled==0.4.2
wled==0.4.3
# homeassistant.components.xbee
xbee-helper==0.0.7
@@ -2242,7 +2242,7 @@ zengge==0.2
zeroconf==0.27.1
# homeassistant.components.zha
zha-quirks==0.0.39
zha-quirks==0.0.40
# homeassistant.components.zhong_hong
zhong_hong_hvac==1.0.9

View File

@@ -66,7 +66,7 @@ aio_georss_gdacs==0.3
aioambient==1.1.1
# homeassistant.components.asuswrt
aioasuswrt==1.2.5
aioasuswrt==1.2.6
# homeassistant.components.aws
aiobotocore==0.11.1
@@ -147,7 +147,7 @@ async-upnp-client==0.14.13
av==8.0.2
# homeassistant.components.axis
axis==29
axis==30
# homeassistant.components.homekit
base36==0.1.1
@@ -321,7 +321,7 @@ hole==0.5.1
holidays==0.10.2
# homeassistant.components.frontend
home-assistant-frontend==20200603.2
home-assistant-frontend==20200603.3
# homeassistant.components.zwave
homeassistant-pyozw==0.1.10
@@ -545,7 +545,7 @@ pychromecast==6.0.0
pycoolmasternet==0.0.4
# homeassistant.components.daikin
pydaikin==2.1.1
pydaikin==2.1.2
# homeassistant.components.deconz
pydeconz==71
@@ -901,7 +901,7 @@ wiffi==1.0.0
withings-api==2.1.3
# homeassistant.components.wled
wled==0.4.2
wled==0.4.3
# homeassistant.components.bluesound
# homeassistant.components.rest
@@ -918,7 +918,7 @@ ya_ma==0.3.8
zeroconf==0.27.1
# homeassistant.components.zha
zha-quirks==0.0.39
zha-quirks==0.0.40
# homeassistant.components.zha
zigpy-cc==0.4.4

View File

@@ -114,12 +114,14 @@ async def test_view(hass):
"""Test view."""
hass.config_entries.flow.async_init = AsyncMock()
request = aiohttp.MockRequest(b"", query_string="code=test_code")
request = aiohttp.MockRequest(
b"", query_string="code=test_code", mock_source="test"
)
request.app = {"hass": hass}
view = config_flow.AmbiclimateAuthCallbackView()
assert await view.get(request) == "OK!"
request = aiohttp.MockRequest(b"", query_string="")
request = aiohttp.MockRequest(b"", query_string="", mock_source="test")
request.app = {"hass": hass}
view = config_flow.AmbiclimateAuthCallbackView()
assert await view.get(request) == "No code"

View File

@@ -141,7 +141,7 @@ async def test_handler_google_actions_disabled(hass, mock_cloud_fixture):
assert resp["payload"]["errorCode"] == "deviceTurnedOff"
async def test_webhook_msg(hass):
async def test_webhook_msg(hass, caplog):
"""Test webhook msg."""
with patch("hass_nabucasa.Cloud.start"):
setup = await async_setup_component(hass, "cloud", {"cloud": {}})
@@ -151,7 +151,14 @@ async def test_webhook_msg(hass):
await cloud.client.prefs.async_initialize()
await cloud.client.prefs.async_update(
cloudhooks={
"hello": {"webhook_id": "mock-webhook-id", "cloudhook_id": "mock-cloud-id"}
"mock-webhook-id": {
"webhook_id": "mock-webhook-id",
"cloudhook_id": "mock-cloud-id",
},
"no-longere-existing": {
"webhook_id": "no-longere-existing",
"cloudhook_id": "mock-nonexisting-id",
},
}
)
@@ -183,6 +190,31 @@ async def test_webhook_msg(hass):
assert len(received) == 1
assert await received[0].json() == {"hello": "world"}
# Non existing webhook
caplog.clear()
response = await cloud.client.async_webhook_message(
{
"cloudhook_id": "mock-nonexisting-id",
"body": '{"nonexisting": "payload"}',
"headers": {"content-type": "application/json"},
"method": "POST",
"query": None,
}
)
assert response == {
"status": 200,
"body": None,
"headers": {"Content-Type": "application/octet-stream"},
}
assert (
"Received message for unregistered webhook no-longere-existing from cloud"
in caplog.text
)
assert '{"nonexisting": "payload"}' in caplog.text
async def test_google_config_expose_entity(hass, mock_cloud_setup, mock_cloud_login):
"""Test Google config exposing entity method uses latest config."""

View File

@@ -6,7 +6,7 @@ from aiohttp import ClientError
from aiohttp.web_exceptions import HTTPForbidden
import pytest
from homeassistant.components.daikin.const import KEY_HOSTNAME, KEY_IP, KEY_MAC
from homeassistant.components.daikin.const import KEY_IP, KEY_MAC
from homeassistant.config_entries import (
SOURCE_DISCOVERY,
SOURCE_IMPORT,
@@ -25,7 +25,6 @@ from tests.common import MockConfigEntry
MAC = "AABBCCDDEEFF"
HOST = "127.0.0.1"
HOSTNAME = "DaikinUNIQUE.local"
@pytest.fixture
@@ -42,6 +41,16 @@ def mock_daikin():
yield Appliance
@pytest.fixture
def mock_daikin_discovery():
"""Mock pydaikin Discovery."""
with patch("homeassistant.components.daikin.config_flow.Discovery") as Discovery:
Discovery.poll = PropertyMock(
return_value={"127.0.01": {"mac": "AABBCCDDEEFF", "id": "test"}}
)
yield Discovery
async def test_user(hass, mock_daikin):
"""Test user config."""
result = await hass.config_entries.flow.async_init(
@@ -113,10 +122,12 @@ async def test_device_abort(hass, mock_daikin, s_effect, reason):
"source, data, unique_id",
[
(SOURCE_DISCOVERY, {KEY_IP: HOST, KEY_MAC: MAC}, MAC),
(SOURCE_ZEROCONF, {CONF_HOST: HOST, KEY_HOSTNAME: HOSTNAME}, HOSTNAME),
(SOURCE_ZEROCONF, {CONF_HOST: HOST}, MAC),
],
)
async def test_discovery_zeroconf(hass, mock_daikin, source, data, unique_id):
async def test_discovery_zeroconf(
hass, mock_daikin, mock_daikin_discovery, source, data, unique_id
):
"""Test discovery/zeroconf step."""
result = await hass.config_entries.flow.async_init(
"daikin", context={"source": source}, data=data,

View File

@@ -104,7 +104,7 @@ async def test_hassio_discovery_startup_done(hass, aioclient_mock, hassio_client
await async_setup_component(hass, "hassio", {})
await hass.async_block_till_done()
assert aioclient_mock.call_count == 3
assert aioclient_mock.call_count == 2
assert mock_mqtt.called
mock_mqtt.assert_called_with(
{

View File

@@ -222,11 +222,8 @@ class TestComponentHistory(unittest.TestCase):
# will happen with encoding a native state
input_state = states["media_player.test"][1]
orig_last_changed = json.dumps(
process_timestamp(input_state.last_changed.replace(microsecond=0)),
cls=JSONEncoder,
process_timestamp(input_state.last_changed), cls=JSONEncoder,
).replace('"', "")
if orig_last_changed.endswith("+00:00"):
orig_last_changed = f"{orig_last_changed[:-6]}{recorder.models.DB_TIMEZONE}"
orig_state = input_state.state
states["media_player.test"][1] = {
"last_changed": orig_last_changed,

View File

@@ -1353,3 +1353,68 @@ async def test_logbook_describe_event(hass, hass_client):
assert event["name"] == "Test Name"
assert event["message"] == "tested a message"
assert event["domain"] == "test_domain"
async def test_exclude_described_event(hass, hass_client):
"""Test exclusions of events that are described by another integration."""
name = "My Automation Rule"
entity_id = "automation.excluded_rule"
entity_id2 = "automation.included_rule"
entity_id3 = "sensor.excluded_domain"
await hass.async_add_executor_job(init_recorder_component, hass)
assert await async_setup_component(
hass,
logbook.DOMAIN,
{
logbook.DOMAIN: {
logbook.CONF_EXCLUDE: {
logbook.CONF_DOMAINS: ["sensor"],
logbook.CONF_ENTITIES: [entity_id],
}
}
},
)
with patch(
"homeassistant.util.dt.utcnow",
return_value=dt_util.utcnow() - timedelta(seconds=5),
):
hass.bus.async_fire(
"some_automation_event",
{logbook.ATTR_NAME: name, logbook.ATTR_ENTITY_ID: entity_id},
)
hass.bus.async_fire(
"some_automation_event",
{logbook.ATTR_NAME: name, logbook.ATTR_ENTITY_ID: entity_id2},
)
hass.bus.async_fire(
"some_event", {logbook.ATTR_NAME: name, logbook.ATTR_ENTITY_ID: entity_id3}
)
await hass.async_block_till_done()
await hass.async_add_executor_job(
hass.data[recorder.DATA_INSTANCE].block_till_done
)
def _describe(event):
"""Describe an event."""
return {
"name": "Test Name",
"message": "tested a message",
"entity_id": event.data.get(ATTR_ENTITY_ID),
}
hass.components.logbook.async_describe_event(
"automation", "some_automation_event", _describe
)
hass.components.logbook.async_describe_event("sensor", "some_event", _describe)
client = await hass_client()
response = await client.get("/api/logbook")
results = await response.json()
assert len(results) == 1
event = results[0]
assert event["name"] == "Test Name"
assert event["message"] == "tested a message"
assert event["domain"] == "automation"
assert event["entity_id"] == "automation.included_rule"

View File

@@ -405,6 +405,56 @@ async def test_option_flow(hass):
}
async def test_missing_option_flow(hass):
"""Test config options flow selection when no options stored."""
mock_plex_server = MockPlexServer()
entry = MockConfigEntry(
domain=DOMAIN,
data=DEFAULT_DATA,
options=None,
unique_id=DEFAULT_DATA["server_id"],
)
with patch("plexapi.server.PlexServer", return_value=mock_plex_server), patch(
"homeassistant.components.plex.PlexWebsocket.listen"
) as mock_listen:
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert mock_listen.called
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert entry.state == ENTRY_STATE_LOADED
result = await hass.config_entries.options.async_init(
entry.entry_id, context={"source": "test"}, data=None
)
assert result["type"] == "form"
assert result["step_id"] == "plex_mp_settings"
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
CONF_USE_EPISODE_ART: True,
CONF_IGNORE_NEW_SHARED_USERS: True,
CONF_MONITORED_USERS: list(mock_plex_server.accounts),
},
)
assert result["type"] == "create_entry"
assert result["data"] == {
MP_DOMAIN: {
CONF_USE_EPISODE_ART: True,
CONF_IGNORE_NEW_SHARED_USERS: True,
CONF_MONITORED_USERS: {
user: {"enabled": True} for user in mock_plex_server.accounts
},
CONF_IGNORE_PLEX_WEB_CLIENTS: False,
}
}
async def test_option_flow_new_users_available(hass, caplog):
"""Test config options multiselect defaults when new Plex users are seen."""

View File

@@ -22,12 +22,14 @@ from homeassistant.const import (
EVENT_HOMEASSISTANT_CLOSE,
EVENT_HOMEASSISTANT_FINAL_WRITE,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STARTED,
EVENT_HOMEASSISTANT_STOP,
EVENT_SERVICE_REGISTERED,
EVENT_SERVICE_REMOVED,
EVENT_STATE_CHANGED,
EVENT_TIME_CHANGED,
EVENT_TIMER_OUT_OF_SYNC,
MATCH_ALL,
__version__,
)
import homeassistant.core as ha
@@ -1333,3 +1335,35 @@ async def test_additional_data_in_core_config(hass, hass_storage):
}
await config.async_load()
assert config.location_name == "Test Name"
async def test_start_events(hass):
"""Test events fired when starting Home Assistant."""
hass.state = ha.CoreState.not_running
all_events = []
@ha.callback
def capture_events(ev):
all_events.append(ev.event_type)
hass.bus.async_listen(MATCH_ALL, capture_events)
core_states = []
@ha.callback
def capture_core_state(_):
core_states.append(hass.state)
hass.bus.async_listen(EVENT_CORE_CONFIG_UPDATE, capture_core_state)
await hass.async_start()
await hass.async_block_till_done()
assert all_events == [
EVENT_CORE_CONFIG_UPDATE,
EVENT_HOMEASSISTANT_START,
EVENT_CORE_CONFIG_UPDATE,
EVENT_HOMEASSISTANT_STARTED,
]
assert core_states == [ha.CoreState.starting, ha.CoreState.running]

View File

@@ -5,14 +5,14 @@ from homeassistant.util import aiohttp
async def test_request_json():
"""Test a JSON request."""
request = aiohttp.MockRequest(b'{"hello": 2}')
request = aiohttp.MockRequest(b'{"hello": 2}', mock_source="test")
assert request.status == 200
assert await request.json() == {"hello": 2}
async def test_request_text():
"""Test a JSON request."""
request = aiohttp.MockRequest(b"hello", status=201)
request = aiohttp.MockRequest(b"hello", status=201, mock_source="test")
assert request.status == 201
assert await request.text() == "hello"
@@ -20,7 +20,7 @@ async def test_request_text():
async def test_request_post_query():
"""Test a JSON request."""
request = aiohttp.MockRequest(
b"hello=2&post=true", query_string="get=true", method="POST"
b"hello=2&post=true", query_string="get=true", method="POST", mock_source="test"
)
assert request.method == "POST"
assert await request.post() == {"hello": "2", "post": "true"}