mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
commit
4f8a93fb3e
@ -3,7 +3,7 @@
|
||||
"name": "Genius Hub",
|
||||
"documentation": "https://www.home-assistant.io/components/geniushub",
|
||||
"requirements": [
|
||||
"geniushub-client==0.4.15"
|
||||
"geniushub-client==0.5.00"
|
||||
],
|
||||
"dependencies": [],
|
||||
"codeowners": ["@zxdavb"]
|
||||
|
@ -1,5 +1,5 @@
|
||||
"""Provide CORS support for the HTTP component."""
|
||||
from aiohttp.web_urldispatcher import Resource, ResourceRoute
|
||||
from aiohttp.web_urldispatcher import Resource, ResourceRoute, StaticResource
|
||||
from aiohttp.hdrs import ACCEPT, CONTENT_TYPE, ORIGIN, AUTHORIZATION
|
||||
|
||||
from homeassistant.const import (
|
||||
@ -9,7 +9,7 @@ from homeassistant.core import callback
|
||||
ALLOWED_CORS_HEADERS = [
|
||||
ORIGIN, ACCEPT, HTTP_HEADER_X_REQUESTED_WITH, CONTENT_TYPE,
|
||||
HTTP_HEADER_HA_AUTH, AUTHORIZATION]
|
||||
VALID_CORS_TYPES = (Resource, ResourceRoute)
|
||||
VALID_CORS_TYPES = (Resource, ResourceRoute, StaticResource)
|
||||
|
||||
|
||||
@callback
|
||||
@ -56,7 +56,7 @@ def setup_cors(app, origins):
|
||||
|
||||
async def cors_startup(app):
|
||||
"""Initialize CORS when app starts up."""
|
||||
for route in list(app.router.routes()):
|
||||
_allow_cors(route)
|
||||
for resource in list(app.router.resources()):
|
||||
_allow_cors(resource)
|
||||
|
||||
app.on_startup.append(cors_startup)
|
||||
|
@ -8,7 +8,8 @@ from homeassistant.components.climate.const import (
|
||||
ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW, FAN_AUTO, FAN_ON,
|
||||
HVAC_MODE_AUTO, HVAC_MODE_COOL, HVAC_MODE_HEAT, HVAC_MODE_OFF,
|
||||
SUPPORT_PRESET_MODE, SUPPORT_FAN_MODE, SUPPORT_TARGET_TEMPERATURE,
|
||||
SUPPORT_TARGET_TEMPERATURE_RANGE, PRESET_AWAY, PRESET_ECO, PRESET_NONE)
|
||||
SUPPORT_TARGET_TEMPERATURE_RANGE, PRESET_AWAY, PRESET_ECO, PRESET_NONE,
|
||||
CURRENT_HVAC_HEAT, CURRENT_HVAC_IDLE, CURRENT_HVAC_COOL)
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE, CONF_SCAN_INTERVAL, TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
@ -28,6 +29,21 @@ NEST_MODE_HEAT = 'heat'
|
||||
NEST_MODE_COOL = 'cool'
|
||||
NEST_MODE_OFF = 'off'
|
||||
|
||||
MODE_HASS_TO_NEST = {
|
||||
HVAC_MODE_AUTO: NEST_MODE_HEAT_COOL,
|
||||
HVAC_MODE_HEAT: NEST_MODE_HEAT,
|
||||
HVAC_MODE_COOL: NEST_MODE_COOL,
|
||||
HVAC_MODE_OFF: NEST_MODE_OFF,
|
||||
}
|
||||
|
||||
MODE_NEST_TO_HASS = {v: k for k, v in MODE_HASS_TO_NEST.items()}
|
||||
|
||||
ACTION_NEST_TO_HASS = {
|
||||
'off': CURRENT_HVAC_IDLE,
|
||||
'heating': CURRENT_HVAC_HEAT,
|
||||
'cooling': CURRENT_HVAC_COOL,
|
||||
}
|
||||
|
||||
PRESET_MODES = [PRESET_NONE, PRESET_AWAY, PRESET_ECO]
|
||||
|
||||
|
||||
@ -95,6 +111,7 @@ class NestThermostat(ClimateDevice):
|
||||
self._temperature = None
|
||||
self._temperature_scale = None
|
||||
self._mode = None
|
||||
self._action = None
|
||||
self._fan = None
|
||||
self._eco_temperature = None
|
||||
self._is_locked = None
|
||||
@ -157,15 +174,16 @@ class NestThermostat(ClimateDevice):
|
||||
@property
|
||||
def hvac_mode(self):
|
||||
"""Return current operation ie. heat, cool, idle."""
|
||||
if self._mode in \
|
||||
(NEST_MODE_HEAT, NEST_MODE_COOL, NEST_MODE_OFF):
|
||||
return self._mode
|
||||
if self._mode == NEST_MODE_ECO:
|
||||
# We assume the first operation in operation list is the main one
|
||||
return self._operation_list[0]
|
||||
if self._mode == NEST_MODE_HEAT_COOL:
|
||||
return HVAC_MODE_AUTO
|
||||
return None
|
||||
|
||||
return MODE_NEST_TO_HASS[self._mode]
|
||||
|
||||
@property
|
||||
def hvac_action(self):
|
||||
"""Return the current hvac action."""
|
||||
return ACTION_NEST_TO_HASS[self._action]
|
||||
|
||||
@property
|
||||
def target_temperature(self):
|
||||
@ -216,16 +234,7 @@ class NestThermostat(ClimateDevice):
|
||||
|
||||
def set_hvac_mode(self, hvac_mode):
|
||||
"""Set operation mode."""
|
||||
if hvac_mode in (HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_OFF):
|
||||
device_mode = hvac_mode
|
||||
elif hvac_mode == HVAC_MODE_AUTO:
|
||||
device_mode = NEST_MODE_HEAT_COOL
|
||||
else:
|
||||
device_mode = HVAC_MODE_OFF
|
||||
_LOGGER.error(
|
||||
"An error occurred while setting device mode. "
|
||||
"Invalid operation mode: %s", hvac_mode)
|
||||
self.device.mode = device_mode
|
||||
self.device.mode = MODE_HASS_TO_NEST[hvac_mode]
|
||||
|
||||
@property
|
||||
def hvac_modes(self):
|
||||
@ -259,7 +268,7 @@ class NestThermostat(ClimateDevice):
|
||||
self.structure.away = True
|
||||
|
||||
if self.preset_mode == PRESET_ECO:
|
||||
self.device.mode = self._operation_list[0]
|
||||
self.device.mode = MODE_HASS_TO_NEST[self._operation_list[0]]
|
||||
elif preset_mode == PRESET_ECO:
|
||||
self.device.mode = NEST_MODE_ECO
|
||||
|
||||
@ -301,6 +310,7 @@ class NestThermostat(ClimateDevice):
|
||||
self._humidity = self.device.humidity
|
||||
self._temperature = self.device.temperature
|
||||
self._mode = self.device.mode
|
||||
self._action = self.device.hvac_state
|
||||
self._target_temperature = self.device.target
|
||||
self._fan = self.device.fan
|
||||
self._away = self.structure.away == 'away'
|
||||
|
@ -2,7 +2,7 @@
|
||||
"""Constants used by Home Assistant components."""
|
||||
MAJOR_VERSION = 0
|
||||
MINOR_VERSION = 96
|
||||
PATCH_VERSION = '4'
|
||||
PATCH_VERSION = '5'
|
||||
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
||||
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
||||
REQUIRED_PYTHON_VER = (3, 5, 3)
|
||||
|
@ -505,7 +505,7 @@ gearbest_parser==1.0.7
|
||||
geizhals==0.0.9
|
||||
|
||||
# homeassistant.components.geniushub
|
||||
geniushub-client==0.4.15
|
||||
geniushub-client==0.5.00
|
||||
|
||||
# homeassistant.components.geo_json_events
|
||||
# homeassistant.components.nsw_rural_fire_service_feed
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""Test cors for the HTTP component."""
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from aiohttp import web
|
||||
@ -152,3 +153,22 @@ async def test_cors_works_with_frontend(hass, hass_client):
|
||||
client = await hass_client()
|
||||
resp = await client.get('/')
|
||||
assert resp.status == 200
|
||||
|
||||
|
||||
async def test_cors_on_static_files(hass, hass_client):
|
||||
"""Test that we enable CORS for static files."""
|
||||
assert await async_setup_component(hass, 'frontend', {
|
||||
'http': {
|
||||
'cors_allowed_origins': ['http://www.example.com']
|
||||
}
|
||||
})
|
||||
hass.http.register_static_path('/something', Path(__file__).parent)
|
||||
|
||||
client = await hass_client()
|
||||
resp = await client.options('/something/__init__.py', headers={
|
||||
'origin': 'http://www.example.com',
|
||||
ACCESS_CONTROL_REQUEST_METHOD: 'GET',
|
||||
})
|
||||
assert resp.status == 200
|
||||
assert resp.headers[ACCESS_CONTROL_ALLOW_ORIGIN] == \
|
||||
'http://www.example.com'
|
||||
|
Loading…
x
Reference in New Issue
Block a user