Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:thibmaek/home-assistant into feature…
Browse files Browse the repository at this point in the history
…/nmbs-sensor

* 'dev' of github.com:thibmaek/home-assistant:
  Add raw service data to event (home-assistant#19163)
  Updated frontend to 20181210.1
  Google assistant fix target temp for *F values. (home-assistant#19083)
  Fix lovelace save (home-assistant#19162)
  Drop OwnTracks bad packets (home-assistant#19161)
  home-assistant#18645: revert heat-cool -> auto change
  home-assistant#18645: Remove un-used constants.
  home-assistant#18645: Fix climate mode mapping.
  • Loading branch information
thibmaek committed Dec 10, 2018
2 parents e1b00f1 + 5958178 commit 5d46f27
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 24 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from homeassistant.helpers.translation import async_get_translations
from homeassistant.loader import bind_hass

REQUIREMENTS = ['home-assistant-frontend==20181210.0']
REQUIREMENTS = ['home-assistant-frontend==20181210.1']

DOMAIN = 'frontend'
DEPENDENCIES = ['api', 'websocket_api', 'http', 'system_log',
Expand Down
2 changes: 0 additions & 2 deletions homeassistant/components/google_assistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
'media_player', 'scene', 'script', 'switch', 'vacuum', 'lock',
]
DEFAULT_ALLOW_UNLOCK = False
CLIMATE_MODE_HEATCOOL = 'heatcool'
CLIMATE_SUPPORTED_MODES = {'heat', 'cool', 'off', 'on', CLIMATE_MODE_HEATCOOL}

PREFIX_TYPES = 'action.devices.types.'
TYPE_LIGHT = PREFIX_TYPES + 'LIGHT'
Expand Down
17 changes: 14 additions & 3 deletions homeassistant/components/google_assistant/trait.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ class TemperatureSettingTrait(_Trait):
climate.STATE_COOL: 'cool',
climate.STATE_OFF: 'off',
climate.STATE_AUTO: 'heatcool',
climate.STATE_FAN_ONLY: 'fan-only',
climate.STATE_DRY: 'dry',
climate.STATE_ECO: 'eco'
}
google_to_hass = {value: key for key, value in hass_to_google.items()}

Expand Down Expand Up @@ -588,8 +591,11 @@ async def execute(self, command, params):
max_temp = self.state.attributes[climate.ATTR_MAX_TEMP]

if command == COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT:
temp = temp_util.convert(params['thermostatTemperatureSetpoint'],
TEMP_CELSIUS, unit)
temp = temp_util.convert(
params['thermostatTemperatureSetpoint'], TEMP_CELSIUS,
unit)
if unit == TEMP_FAHRENHEIT:
temp = round(temp)

if temp < min_temp or temp > max_temp:
raise SmartHomeError(
Expand All @@ -607,6 +613,8 @@ async def execute(self, command, params):
temp_high = temp_util.convert(
params['thermostatTemperatureSetpointHigh'], TEMP_CELSIUS,
unit)
if unit == TEMP_FAHRENHEIT:
temp_high = round(temp_high)

if temp_high < min_temp or temp_high > max_temp:
raise SmartHomeError(
Expand All @@ -615,7 +623,10 @@ async def execute(self, command, params):
"{} and {}".format(min_temp, max_temp))

temp_low = temp_util.convert(
params['thermostatTemperatureSetpointLow'], TEMP_CELSIUS, unit)
params['thermostatTemperatureSetpointLow'], TEMP_CELSIUS,
unit)
if unit == TEMP_FAHRENHEIT:
temp_low = round(temp_low)

if temp_low < min_temp or temp_low > max_temp:
raise SmartHomeError(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/lovelace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ async def async_load(self, force):

async def async_save(self, config):
"""Save config."""
self._data = {'config': config}
await self._store.async_save(config)
self._data['config'] = config
await self._store.async_save(self._data)


class LovelaceYAML:
Expand Down
22 changes: 15 additions & 7 deletions homeassistant/components/owntracks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,18 @@ async def async_handle_mqtt_message(topic, payload, qos):


async def handle_webhook(hass, webhook_id, request):
"""Handle webhook callback."""
"""Handle webhook callback.
iOS sets the "topic" as part of the payload.
Android does not set a topic but adds headers to the request.
"""
context = hass.data[DOMAIN]['context']
message = await request.json()

try:
message = await request.json()
except ValueError:
_LOGGER.warning('Received invalid JSON from OwnTracks')
return json_response([])

# Android doesn't populate topic
if 'topic' not in message:
Expand All @@ -129,11 +138,10 @@ async def handle_webhook(hass, webhook_id, request):
device = headers.get('X-Limit-D', user)

if user is None:
_LOGGER.warning('Set a username in Connection -> Identification')
return json_response(
{'error': 'You need to supply username.'},
status=400
)
_LOGGER.warning('No topic or user found in message. If on Android,'
' set a username in Connection -> Identification')
# Keep it as a 200 response so the incorrect packet is discarded
return json_response([])

topic_base = re.sub('/#$', '', context.mqtt_topic)
message['topic'] = '{}/{}/{}'.format(topic_base, user, device)
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,9 +1098,11 @@ async def async_call(self, domain: str, service: str,
raise ServiceNotFound(domain, service) from None

if handler.schema:
service_data = handler.schema(service_data)
processed_data = handler.schema(service_data)
else:
processed_data = service_data

service_call = ServiceCall(domain, service, service_data, context)
service_call = ServiceCall(domain, service, processed_data, context)

self._hass.bus.async_fire(EVENT_CALL_SERVICE, {
ATTR_DOMAIN: domain.lower(),
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ hole==0.3.0
holidays==0.9.8

# homeassistant.components.frontend
home-assistant-frontend==20181210.0
home-assistant-frontend==20181210.1

# homeassistant.components.zwave
homeassistant-pyozw==0.1.1
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ hdate==0.7.5
holidays==0.9.8

# homeassistant.components.frontend
home-assistant-frontend==20181210.0
home-assistant-frontend==20181210.1

# homeassistant.components.homematicip_cloud
homematicip==0.9.8
Expand Down
2 changes: 1 addition & 1 deletion tests/components/lovelace/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def test_lovelace_from_storage(hass, hass_ws_client, hass_storage):
response = await client.receive_json()
assert response['success']
assert hass_storage[lovelace.STORAGE_KEY]['data'] == {
'yo': 'hello'
'config': {'yo': 'hello'}
}

# Load new config
Expand Down
25 changes: 22 additions & 3 deletions tests/components/owntracks/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_handle_value_error(mock_client):


@asyncio.coroutine
def test_returns_error_missing_username(mock_client):
def test_returns_error_missing_username(mock_client, caplog):
"""Test that an error is returned when username is missing."""
resp = yield from mock_client.post(
'/api/webhook/owntracks_test',
Expand All @@ -120,10 +120,29 @@ def test_returns_error_missing_username(mock_client):
}
)

assert resp.status == 400
# Needs to be 200 or OwnTracks keeps retrying bad packet.
assert resp.status == 200
json = yield from resp.json()
assert json == []
assert 'No topic or user found' in caplog.text


@asyncio.coroutine
def test_returns_error_incorrect_json(mock_client, caplog):
"""Test that an error is returned when username is missing."""
resp = yield from mock_client.post(
'/api/webhook/owntracks_test',
data='not json',
headers={
'X-Limit-d': 'Pixel',
}
)

# Needs to be 200 or OwnTracks keeps retrying bad packet.
assert resp.status == 200
json = yield from resp.json()
assert json == {'error': 'You need to supply username.'}
assert json == []
assert 'invalid JSON' in caplog.text


@asyncio.coroutine
Expand Down
27 changes: 26 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from datetime import datetime, timedelta
from tempfile import TemporaryDirectory

import voluptuous as vol
import pytz
import pytest

Expand All @@ -21,7 +22,7 @@
__version__, EVENT_STATE_CHANGED, ATTR_FRIENDLY_NAME, CONF_UNIT_SYSTEM,
ATTR_NOW, EVENT_TIME_CHANGED, EVENT_TIMER_OUT_OF_SYNC, ATTR_SECONDS,
EVENT_HOMEASSISTANT_STOP, EVENT_HOMEASSISTANT_CLOSE,
EVENT_SERVICE_REGISTERED, EVENT_SERVICE_REMOVED)
EVENT_SERVICE_REGISTERED, EVENT_SERVICE_REMOVED, EVENT_CALL_SERVICE)

from tests.common import get_test_home_assistant, async_mock_service

Expand Down Expand Up @@ -1000,3 +1001,27 @@ async def handle_outer(call):
assert len(calls) == 4
assert [call.service for call in calls] == [
'outer', 'inner', 'inner', 'outer']


async def test_service_call_event_contains_original_data(hass):
"""Test that service call event contains original data."""
events = []

@ha.callback
def callback(event):
events.append(event)

hass.bus.async_listen(EVENT_CALL_SERVICE, callback)

calls = async_mock_service(hass, 'test', 'service', vol.Schema({
'number': vol.Coerce(int)
}))

await hass.services.async_call('test', 'service', {
'number': '23'
}, blocking=True)
await hass.async_block_till_done()
assert len(events) == 1
assert events[0].data['service_data']['number'] == '23'
assert len(calls) == 1
assert calls[0].data['number'] == 23

0 comments on commit 5d46f27

Please sign in to comment.