Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into feature/nmbs-sensor

* 'dev' of https://github.com/home-assistant/home-assistant: (325 commits)
  Update translations
  Updated frontend to 20181210.0
  Lovelace using storage (home-assistant#19101)
  Update pygtfs to upstream's 0.1.5 (home-assistant#19151)
  Update radiotherm to 2.0.0 and handle change in tstat error detection (home-assistant#19107)
  Upgrade sphinx-autodoc-typehints to 1.5.2 (home-assistant#19140)
  Update geizhals dependency (home-assistant#19152)
  Upgrade mypy to 0.650 (home-assistant#19150)
  Upgrade upcloud-api to 0.4.3
  Upgrade youtube_dl to 2018.12.03 (home-assistant#19139)
  Upgrade slacker to 0.12.0
  Add code support for iAlarm (home-assistant#19124)
  Fixed doorbird config without events (empty list) (home-assistant#19121)
  Remove marking device tracker stale if state is stale (home-assistant#19133)
  Update Google Assistant services description and request sync timeout (home-assistant#19113)
  update edp_redy version (home-assistant#19078)
  Add Philips Moonlight Bedside Lamp support (home-assistant#18496)
  Upgrade Mill library (home-assistant#19117)
  Don't avoid async_schedule_update_ha_state by returning false (home-assistant#19102)
  Fix the Xiaomi Aqara Cube rotate event of the LAN protocol 2.0 (Closes: home-assistant#18199) (home-assistant#19104)
  ...
  • Loading branch information
thibmaek committed Dec 10, 2018
2 parents 47bec52 + fe2d24c commit 39a88b0
Show file tree
Hide file tree
Showing 593 changed files with 19,277 additions and 10,749 deletions.
14 changes: 12 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 @@ -600,6 +609,7 @@ omit =
homeassistant/components/media_player/nadtcp.py
homeassistant/components/media_player/onkyo.py
homeassistant/components/media_player/openhome.py
homeassistant/components/media_player/panasonic_bluray.py
homeassistant/components/media_player/panasonic_viera.py
homeassistant/components/media_player/pandora.py
homeassistant/components/media_player/philips_js.py
Expand Down Expand Up @@ -636,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 @@ -779,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
27 changes: 20 additions & 7 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 Expand Up @@ -118,6 +113,10 @@ async def async_get_user(self, user_id: str) -> Optional[models.User]:
"""Retrieve a user."""
return await self._store.async_get_user(user_id)

async def async_get_group(self, group_id: str) -> Optional[models.Group]:
"""Retrieve all groups."""
return await self._store.async_get_group(group_id)

async def async_get_user_by_credentials(
self, credentials: models.Credentials) -> Optional[models.User]:
"""Get a user by credential, return None if not found."""
Expand All @@ -128,13 +127,15 @@ async def async_get_user_by_credentials(

return None

async def async_create_system_user(self, name: str) -> models.User:
async def async_create_system_user(
self, name: str,
group_ids: Optional[List[str]] = None) -> models.User:
"""Create a system user."""
user = await self._store.async_create_user(
name=name,
system_generated=True,
is_active=True,
group_ids=[],
group_ids=group_ids or [],
)

self.hass.bus.async_fire(EVENT_USER_ADDED, {
Expand Down Expand Up @@ -184,6 +185,7 @@ async def async_get_or_create_user(self, credentials: models.Credentials) \
credentials=credentials,
name=info.name,
is_active=info.is_active,
group_ids=[GROUP_ID_ADMIN],
)

self.hass.bus.async_fire(EVENT_USER_ADDED, {
Expand Down Expand Up @@ -213,6 +215,17 @@ async def async_remove_user(self, user: models.User) -> None:
'user_id': user.id
})

async def async_update_user(self, user: models.User,
name: Optional[str] = None,
group_ids: Optional[List[str]] = None) -> None:
"""Update a user."""
kwargs = {} # type: Dict[str,Any]
if name is not None:
kwargs['name'] = name
if group_ids is not None:
kwargs['group_ids'] = group_ids
await self._store.async_update_user(user, **kwargs)

async def async_activate_user(self, user: models.User) -> None:
"""Activate a user."""
await self._store.async_activate_user(user)
Expand Down
51 changes: 48 additions & 3 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 All @@ -45,6 +47,14 @@ async def async_get_groups(self) -> List[models.Group]:

return list(self._groups.values())

async def async_get_group(self, group_id: str) -> Optional[models.Group]:
"""Retrieve all users."""
if self._groups is None:
await self._async_load()
assert self._groups is not None

return self._groups.get(group_id)

async def async_get_users(self) -> List[models.User]:
"""Retrieve all users."""
if self._users is None:
Expand Down Expand Up @@ -86,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 @@ -125,6 +136,33 @@ async def async_remove_user(self, user: models.User) -> None:
self._users.pop(user.id)
self._async_schedule_save()

async def async_update_user(
self, user: models.User, name: Optional[str] = None,
is_active: Optional[bool] = None,
group_ids: Optional[List[str]] = None) -> None:
"""Update a user."""
assert self._groups is not None

if group_ids is not None:
groups = []
for grid in group_ids:
group = self._groups.get(grid)
if group is None:
raise ValueError("Invalid group specified.")
groups.append(group)

user.groups = groups
user.invalidate_permission_cache()

for attr_name, value in (
('name', name),
('is_active', is_active),
):
if value is not None:
setattr(user, attr_name, value)

self._async_schedule_save()

async def async_activate_user(self, user: models.User) -> None:
"""Activate a user."""
user.is_active = True
Expand Down Expand Up @@ -234,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 @@ -339,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 Expand Up @@ -427,10 +471,11 @@ def _data_to_save(self) -> Dict:
for group in self._groups.values():
g_dict = {
'id': group.id,
# Name not read for sys groups. Kept here for backwards compat
'name': group.name
} # type: Dict[str, Any]

if group.id not in (GROUP_ID_READ_ONLY, GROUP_ID_ADMIN):
g_dict['name'] = group.name
g_dict['policy'] = group.policy

groups.append(g_dict)
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
Loading

0 comments on commit 39a88b0

Please sign in to comment.