Skip to content

Commit

Permalink
Merge pull request #19215 from home-assistant/rc
Browse files Browse the repository at this point in the history
0.84
  • Loading branch information
balloob authored Dec 12, 2018
2 parents acd2f55 + 404fbe3 commit 88cda04
Show file tree
Hide file tree
Showing 462 changed files with 14,566 additions and 8,499 deletions.
13 changes: 11 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ omit =
homeassistant/components/hive.py
homeassistant/components/*/hive.py

homeassistant/components/hlk_sw16.py
homeassistant/components/*/hlk_sw16.py

homeassistant/components/homekit_controller/__init__.py
homeassistant/components/*/homekit_controller.py

Expand Down Expand Up @@ -203,6 +206,9 @@ omit =
homeassistant/components/linode.py
homeassistant/components/*/linode.py

homeassistant/components/lightwave.py
homeassistant/components/*/lightwave.py

homeassistant/components/logi_circle.py
homeassistant/components/*/logi_circle.py

Expand Down Expand Up @@ -323,7 +329,8 @@ omit =
homeassistant/components/tahoma.py
homeassistant/components/*/tahoma.py

homeassistant/components/tellduslive.py
homeassistant/components/tellduslive/__init__.py
homeassistant/components/tellduslive/entry.py
homeassistant/components/*/tellduslive.py

homeassistant/components/tellstick.py
Expand Down Expand Up @@ -400,6 +407,8 @@ omit =

homeassistant/components/zha/__init__.py
homeassistant/components/zha/const.py
homeassistant/components/zha/entities/*
homeassistant/components/zha/helpers.py
homeassistant/components/*/zha.py

homeassistant/components/zigbee.py
Expand Down Expand Up @@ -637,7 +646,6 @@ omit =
homeassistant/components/notify/group.py
homeassistant/components/notify/hipchat.py
homeassistant/components/notify/homematic.py
homeassistant/components/notify/instapush.py
homeassistant/components/notify/kodi.py
homeassistant/components/notify/lannouncer.py
homeassistant/components/notify/llamalab_automate.py
Expand Down Expand Up @@ -780,6 +788,7 @@ omit =
homeassistant/components/sensor/pushbullet.py
homeassistant/components/sensor/pvoutput.py
homeassistant/components/sensor/pyload.py
homeassistant/components/sensor/qbittorrent.py
homeassistant/components/sensor/qnap.py
homeassistant/components/sensor/radarr.py
homeassistant/components/sensor/rainbird.py
Expand Down
19 changes: 17 additions & 2 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ homeassistant/components/alarm_control_panel/egardia.py @jeroenterheerdt
homeassistant/components/alarm_control_panel/manual_mqtt.py @colinodell
homeassistant/components/binary_sensor/hikvision.py @mezz64
homeassistant/components/binary_sensor/threshold.py @fabaff
homeassistant/components/binary_sensor/uptimerobot.py @ludeeus
homeassistant/components/camera/yi.py @bachya
homeassistant/components/climate/ephember.py @ttroy50
homeassistant/components/climate/eq3btsmart.py @rytilahti
Expand All @@ -61,9 +62,11 @@ homeassistant/components/cover/group.py @cdce8p
homeassistant/components/cover/template.py @PhracturedBlue
homeassistant/components/device_tracker/asuswrt.py @kennedyshead
homeassistant/components/device_tracker/automatic.py @armills
homeassistant/components/device_tracker/googlehome.py @ludeeus
homeassistant/components/device_tracker/huawei_router.py @abmantis
homeassistant/components/device_tracker/quantum_gateway.py @cisasteelersfan
homeassistant/components/device_tracker/tile.py @bachya
homeassistant/components/device_tracker/traccar.py @ludeeus
homeassistant/components/device_tracker/bt_smarthub.py @jxwolstenholme
homeassistant/components/history_graph.py @andrey-git
homeassistant/components/influx.py @fabaff
Expand Down Expand Up @@ -109,6 +112,7 @@ homeassistant/components/sensor/glances.py @fabaff
homeassistant/components/sensor/gpsd.py @fabaff
homeassistant/components/sensor/irish_rail_transport.py @ttroy50
homeassistant/components/sensor/jewish_calendar.py @tsvi
homeassistant/components/sensor/launch_library.py @ludeeus
homeassistant/components/sensor/linux_battery.py @fabaff
homeassistant/components/sensor/miflora.py @danielhiversen @ChristianKuehnel
homeassistant/components/sensor/min_max.py @fabaff
Expand All @@ -119,6 +123,7 @@ homeassistant/components/sensor/pi_hole.py @fabaff
homeassistant/components/sensor/pollen.py @bachya
homeassistant/components/sensor/pvoutput.py @fabaff
homeassistant/components/sensor/qnap.py @colinodell
homeassistant/components/sensor/ruter.py @ludeeus
homeassistant/components/sensor/scrape.py @fabaff
homeassistant/components/sensor/serial.py @fabaff
homeassistant/components/sensor/seventeentrack.py @bachya
Expand All @@ -128,12 +133,15 @@ homeassistant/components/sensor/sql.py @dgomes
homeassistant/components/sensor/statistics.py @fabaff
homeassistant/components/sensor/swiss*.py @fabaff
homeassistant/components/sensor/sytadin.py @gautric
homeassistant/components/sensor/tautulli.py @ludeeus
homeassistant/components/sensor/time_data.py @fabaff
homeassistant/components/sensor/version.py @fabaff
homeassistant/components/sensor/waqi.py @andrey-git
homeassistant/components/sensor/worldclock.py @fabaff
homeassistant/components/shiftr.py @fabaff
homeassistant/components/spaceapi.py @fabaff
homeassistant/components/switch/switchbot.py @danielhiversen
homeassistant/components/switch/switchmate.py @danielhiversen
homeassistant/components/switch/tplink.py @rytilahti
homeassistant/components/vacuum/roomba.py @pschmitt
homeassistant/components/weather/__init__.py @fabaff
Expand All @@ -157,9 +165,12 @@ homeassistant/components/*/bmw_connected_drive.py @ChristianKuehnel
homeassistant/components/*/broadlink.py @danielhiversen

# C
homeassistant/components/cloudflare.py @ludeeus
homeassistant/components/counter/* @fabaff

# D
homeassistant/components/daikin.py @fredrike @rofrantz
homeassistant/components/*/daikin.py @fredrike @rofrantz
homeassistant/components/*/deconz.py @kane610
homeassistant/components/digital_ocean.py @fabaff
homeassistant/components/*/digital_ocean.py @fabaff
Expand Down Expand Up @@ -204,6 +215,10 @@ homeassistant/components/*/mystrom.py @fabaff
homeassistant/components/openuv/* @bachya
homeassistant/components/*/openuv.py @bachya

# P
homeassistant/components/point/* @fredrike
homeassistant/components/*/point.py @fredrike

# Q
homeassistant/components/qwikswitch.py @kellerza
homeassistant/components/*/qwikswitch.py @kellerza
Expand All @@ -221,8 +236,8 @@ homeassistant/components/*/simplisafe.py @bachya
# T
homeassistant/components/tahoma.py @philklei
homeassistant/components/*/tahoma.py @philklei
homeassistant/components/tellduslive.py @molobrakos @fredrike
homeassistant/components/*/tellduslive.py @molobrakos @fredrike
homeassistant/components/tellduslive/*.py @fredrike
homeassistant/components/*/tellduslive.py @fredrike
homeassistant/components/tesla.py @zabuldon
homeassistant/components/*/tesla.py @zabuldon
homeassistant/components/thethingsnetwork.py @fabaff
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ def __init__(self, hass: HomeAssistant, store: auth_store.AuthStore,
hass, self._async_create_login_flow,
self._async_finish_login_flow)

@property
def active(self) -> bool:
"""Return if any auth providers are registered."""
return bool(self._providers)

@property
def support_legacy(self) -> bool:
"""
Expand Down
13 changes: 11 additions & 2 deletions homeassistant/auth/auth_store.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Storage for auth models."""
import asyncio
from collections import OrderedDict
from datetime import timedelta
import hmac
Expand All @@ -11,7 +12,7 @@

from . import models
from .const import GROUP_ID_ADMIN, GROUP_ID_READ_ONLY
from .permissions import system_policies
from .permissions import PermissionLookup, system_policies
from .permissions.types import PolicyType # noqa: F401

STORAGE_VERSION = 1
Expand All @@ -34,6 +35,7 @@ def __init__(self, hass: HomeAssistant) -> None:
self.hass = hass
self._users = None # type: Optional[Dict[str, models.User]]
self._groups = None # type: Optional[Dict[str, models.Group]]
self._perm_lookup = None # type: Optional[PermissionLookup]
self._store = hass.helpers.storage.Store(STORAGE_VERSION, STORAGE_KEY,
private=True)

Expand Down Expand Up @@ -94,6 +96,7 @@ async def async_create_user(
# Until we get group management, we just put everyone in the
# same group.
'groups': groups,
'perm_lookup': self._perm_lookup,
} # type: Dict[str, Any]

if is_owner is not None:
Expand Down Expand Up @@ -269,13 +272,18 @@ def async_log_refresh_token_usage(

async def _async_load(self) -> None:
"""Load the users."""
data = await self._store.async_load()
[ent_reg, data] = await asyncio.gather(
self.hass.helpers.entity_registry.async_get_registry(),
self._store.async_load(),
)

# Make sure that we're not overriding data if 2 loads happened at the
# same time
if self._users is not None:
return

self._perm_lookup = perm_lookup = PermissionLookup(ent_reg)

if data is None:
self._set_defaults()
return
Expand Down Expand Up @@ -374,6 +382,7 @@ async def _async_load(self) -> None:
is_owner=user_dict['is_owner'],
is_active=user_dict['is_active'],
system_generated=user_dict['system_generated'],
perm_lookup=perm_lookup,
)

for cred_dict in data['credentials']:
Expand Down
10 changes: 7 additions & 3 deletions homeassistant/auth/mfa_modules/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"""
import logging
from collections import OrderedDict
from typing import Any, Dict, Optional, Tuple, List # noqa: F401
from typing import Any, Dict, Optional, List

import attr
import voluptuous as vol

from homeassistant.const import CONF_EXCLUDE, CONF_INCLUDE
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ServiceNotFound
from homeassistant.helpers import config_validation as cv

from . import MultiFactorAuthModule, MULTI_FACTOR_AUTH_MODULES, \
Expand Down Expand Up @@ -314,8 +315,11 @@ async def async_step_setup(
_generate_otp, self._secret, self._count)

assert self._notify_service
await self._auth_module.async_notify(
code, self._notify_service, self._target)
try:
await self._auth_module.async_notify(
code, self._notify_service, self._target)
except ServiceNotFound:
return self.async_abort(reason='notify_service_not_exist')

return self.async_show_form(
step_id='setup',
Expand Down
6 changes: 5 additions & 1 deletion homeassistant/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class User:
"""A user."""

name = attr.ib(type=str) # type: Optional[str]
perm_lookup = attr.ib(
type=perm_mdl.PermissionLookup, cmp=False,
) # type: perm_mdl.PermissionLookup
id = attr.ib(type=str, factory=lambda: uuid.uuid4().hex)
is_owner = attr.ib(type=bool, default=False)
is_active = attr.ib(type=bool, default=False)
Expand Down Expand Up @@ -66,7 +69,8 @@ def permissions(self) -> perm_mdl.AbstractPermissions:

self._permissions = perm_mdl.PolicyPermissions(
perm_mdl.merge_policies([
group.policy for group in self.groups]))
group.policy for group in self.groups]),
self.perm_lookup)

return self._permissions

Expand Down
12 changes: 9 additions & 3 deletions homeassistant/auth/permissions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
"""Permissions for Home Assistant."""
import logging
from typing import ( # noqa: F401
cast, Any, Callable, Dict, List, Mapping, Set, Tuple, Union)
cast, Any, Callable, Dict, List, Mapping, Set, Tuple, Union,
TYPE_CHECKING)

import voluptuous as vol

from .const import CAT_ENTITIES
from .models import PermissionLookup
from .types import PolicyType
from .entities import ENTITY_POLICY_SCHEMA, compile_entities
from .merge import merge_policies # noqa


POLICY_SCHEMA = vol.Schema({
vol.Optional(CAT_ENTITIES): ENTITY_POLICY_SCHEMA
})
Expand Down Expand Up @@ -39,13 +42,16 @@ def check_entity(self, entity_id: str, key: str) -> bool:
class PolicyPermissions(AbstractPermissions):
"""Handle permissions."""

def __init__(self, policy: PolicyType) -> None:
def __init__(self, policy: PolicyType,
perm_lookup: PermissionLookup) -> None:
"""Initialize the permission class."""
self._policy = policy
self._perm_lookup = perm_lookup

def _entity_func(self) -> Callable[[str, str], bool]:
"""Return a function that can test entity access."""
return compile_entities(self._policy.get(CAT_ENTITIES))
return compile_entities(self._policy.get(CAT_ENTITIES),
self._perm_lookup)

def __eq__(self, other: Any) -> bool:
"""Equals check."""
Expand Down
32 changes: 29 additions & 3 deletions homeassistant/auth/permissions/entities.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Entity permissions."""
from functools import wraps
from typing import ( # noqa: F401
Callable, Dict, List, Tuple, Union)
from typing import Callable, List, Union # noqa: F401

import voluptuous as vol

from .const import SUBCAT_ALL, POLICY_READ, POLICY_CONTROL, POLICY_EDIT
from .models import PermissionLookup
from .types import CategoryType, ValueType

SINGLE_ENTITY_SCHEMA = vol.Any(True, vol.Schema({
Expand All @@ -15,6 +15,7 @@
}))

ENTITY_DOMAINS = 'domains'
ENTITY_DEVICE_IDS = 'device_ids'
ENTITY_ENTITY_IDS = 'entity_ids'

ENTITY_VALUES_SCHEMA = vol.Any(True, vol.Schema({
Expand All @@ -23,6 +24,7 @@

ENTITY_POLICY_SCHEMA = vol.Any(True, vol.Schema({
vol.Optional(SUBCAT_ALL): SINGLE_ENTITY_SCHEMA,
vol.Optional(ENTITY_DEVICE_IDS): ENTITY_VALUES_SCHEMA,
vol.Optional(ENTITY_DOMAINS): ENTITY_VALUES_SCHEMA,
vol.Optional(ENTITY_ENTITY_IDS): ENTITY_VALUES_SCHEMA,
}))
Expand All @@ -37,7 +39,7 @@ def _entity_allowed(schema: ValueType, key: str) \
return schema.get(key)


def compile_entities(policy: CategoryType) \
def compile_entities(policy: CategoryType, perm_lookup: PermissionLookup) \
-> Callable[[str, str], bool]:
"""Compile policy into a function that tests policy."""
# None, Empty Dict, False
Expand All @@ -58,6 +60,7 @@ def apply_policy_allow_all(entity_id: str, key: str) -> bool:
assert isinstance(policy, dict)

domains = policy.get(ENTITY_DOMAINS)
device_ids = policy.get(ENTITY_DEVICE_IDS)
entity_ids = policy.get(ENTITY_ENTITY_IDS)
all_entities = policy.get(SUBCAT_ALL)

Expand Down Expand Up @@ -85,6 +88,29 @@ def allowed_entity_id_dict(entity_id: str, key: str) \

funcs.append(allowed_entity_id_dict)

if isinstance(device_ids, bool):
def allowed_device_id_bool(entity_id: str, key: str) \
-> Union[None, bool]:
"""Test if allowed device_id."""
return device_ids

funcs.append(allowed_device_id_bool)

elif device_ids is not None:
def allowed_device_id_dict(entity_id: str, key: str) \
-> Union[None, bool]:
"""Test if allowed device_id."""
entity_entry = perm_lookup.entity_registry.async_get(entity_id)

if entity_entry is None or entity_entry.device_id is None:
return None

return _entity_allowed(
device_ids.get(entity_entry.device_id), key # type: ignore
)

funcs.append(allowed_device_id_dict)

if isinstance(domains, bool):
def allowed_domain_bool(entity_id: str, key: str) \
-> Union[None, bool]:
Expand Down
17 changes: 17 additions & 0 deletions homeassistant/auth/permissions/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Models for permissions."""
from typing import TYPE_CHECKING

import attr

if TYPE_CHECKING:
# pylint: disable=unused-import
from homeassistant.helpers import ( # noqa
entity_registry as ent_reg,
)


@attr.s(slots=True)
class PermissionLookup:
"""Class to hold data for permission lookups."""

entity_registry = attr.ib(type='ent_reg.EntityRegistry')
Loading

0 comments on commit 88cda04

Please sign in to comment.