Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use KEY_HASS [h-z] #112610

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions homeassistant/components/hassio/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from homeassistant.auth.models import User
from homeassistant.auth.providers import homeassistant as auth_ha
from homeassistant.components.http import KEY_HASS_USER, HomeAssistantView
from homeassistant.components.http import KEY_HASS, KEY_HASS_USER, HomeAssistantView
from homeassistant.components.http.data_validator import RequestDataValidator
from homeassistant.core import HomeAssistant, callback
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -74,7 +74,7 @@ class HassIOAuth(HassIOBaseAuth):
async def post(self, request: web.Request, data: dict[str, str]) -> web.Response:
"""Handle auth requests."""
self._check_access(request)
provider = auth_ha.async_get_provider(request.app["hass"])
provider = auth_ha.async_get_provider(request.app[KEY_HASS])

try:
await provider.async_validate_login(
Expand Down Expand Up @@ -104,7 +104,7 @@ class HassIOPasswordReset(HassIOBaseAuth):
async def post(self, request: web.Request, data: dict[str, str]) -> web.Response:
"""Handle password reset requests."""
self._check_access(request)
provider = auth_ha.async_get_provider(request.app["hass"])
provider = auth_ha.async_get_provider(request.app[KEY_HASS])

try:
await provider.async_change_password(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/hassio/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

from homeassistant.components.http import (
KEY_AUTHENTICATED,
KEY_HASS,
KEY_HASS_USER,
HomeAssistantView,
)
from homeassistant.components.onboarding import async_is_onboarded
from homeassistant.core import HomeAssistant

from .const import X_HASS_SOURCE

Expand Down Expand Up @@ -116,7 +116,7 @@ async def _handle(self, request: web.Request, path: str) -> web.StreamResponse:
if path != unquote(path):
return web.Response(status=HTTPStatus.BAD_REQUEST)

hass: HomeAssistant = request.app["hass"]
hass = request.app[KEY_HASS]
is_admin = request[KEY_AUTHENTICATED] and request[KEY_HASS_USER].is_admin
authorized = is_admin

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/history/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import voluptuous as vol

from homeassistant.components import frontend
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http import KEY_HASS, HomeAssistantView
from homeassistant.components.recorder import get_instance, history
from homeassistant.components.recorder.util import session_scope
from homeassistant.const import CONF_EXCLUDE, CONF_INCLUDE
Expand Down Expand Up @@ -74,7 +74,7 @@ async def get(
"filter_entity_id is missing", HTTPStatus.BAD_REQUEST
)

hass = request.app["hass"]
hass = request.app[KEY_HASS]

for entity_id in entity_ids:
if not hass.states.get(entity_id) and not valid_entity_id(entity_id):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/homekit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from homeassistant.components.device_automation.trigger import (
async_validate_trigger_config,
)
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http import KEY_HASS, HomeAssistantView
from homeassistant.components.humidifier import DOMAIN as HUMIDIFIER_DOMAIN
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorDeviceClass
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
Expand Down Expand Up @@ -1163,7 +1163,7 @@
if not request.query_string:
raise Unauthorized()
entry_id, secret = request.query_string.split("-")
hass: HomeAssistant = request.app["hass"]
hass = request.app[KEY_HASS]

Check warning on line 1166 in homeassistant/components/homekit/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/homekit/__init__.py#L1166

Added line #L1166 was not covered by tests
domain_data: dict[str, HomeKitEntryData] = hass.data[DOMAIN]
if (
not (entry_data := domain_data.get(entry_id))
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/html5/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from voluptuous.humanize import humanize_error

from homeassistant.components import websocket_api
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http import KEY_HASS, HomeAssistantView
from homeassistant.components.notify import (
ATTR_DATA,
ATTR_TARGET,
Expand Down Expand Up @@ -231,7 +231,7 @@ async def post(self, request):
self.registrations[name] = data

try:
hass = request.app["hass"]
hass = request.app[KEY_HASS]

await hass.async_add_executor_job(
save_json, self.json_path, self.registrations
Expand Down Expand Up @@ -279,7 +279,7 @@ async def delete(self, request):
reg = self.registrations.pop(found)

try:
hass = request.app["hass"]
hass = request.app[KEY_HASS]

await hass.async_add_executor_job(
save_json, self.json_path, self.registrations
Expand Down Expand Up @@ -388,7 +388,7 @@ async def post(self, request):
)

event_name = f"{NOTIFY_CALLBACK_EVENT}.{event_payload[ATTR_TYPE]}"
request.app["hass"].bus.fire(event_name, event_payload)
request.app[KEY_HASS].bus.fire(event_name, event_payload)
return self.json({"status": "ok", "event": event_payload[ATTR_TYPE]})


Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from aiohttp import hdrs, web
import httpx

from homeassistant.components.http import KEY_AUTHENTICATED, HomeAssistantView
from homeassistant.components.http import KEY_AUTHENTICATED, KEY_HASS, HomeAssistantView
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONTENT_TYPE_MULTIPART, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import Event, HomeAssistant, callback
Expand Down Expand Up @@ -345,7 +345,7 @@ async def image_state_update(_event: EventType[EventStateChangedData]) -> None:
"""Write image to stream."""
event.set()

hass: HomeAssistant = request.app["hass"]
hass = request.app[KEY_HASS]
remove = async_track_state_change_event(
hass,
image_entity.entity_id,
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/image_upload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from PIL import Image, ImageOps, UnidentifiedImageError
import voluptuous as vol

from homeassistant.components.http import KEY_HASS, HomeAssistantView
from homeassistant.components.http.static import CACHE_HEADERS
from homeassistant.components.http.view import HomeAssistantView
from homeassistant.const import CONF_ID
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import collection, config_validation as cv
Expand Down Expand Up @@ -162,7 +162,7 @@ async def post(self, request: web.Request) -> web.Response:
request._client_max_size = MAX_SIZE # pylint: disable=protected-access

data = await request.post()
item = await request.app["hass"].data[DOMAIN].async_create_item(data)
item = await request.app[KEY_HASS].data[DOMAIN].async_create_item(data)
return self.json(item)


Expand Down Expand Up @@ -200,7 +200,7 @@ async def get(
if image_info is None:
raise web.HTTPNotFound()

hass = request.app["hass"]
hass = request.app[KEY_HASS]
target_file = self.image_folder / image_id / f"{width}x{height}"

if not target_file.is_file():
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/intent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class IntentHandleView(http.HomeAssistantView):
)
async def post(self, request: web.Request, data: dict[str, Any]) -> web.Response:
"""Handle intent with name/data."""
hass: HomeAssistant = request.app["hass"]
hass = request.app[http.KEY_HASS]
language = hass.config.language

try:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/ios/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import voluptuous as vol

from homeassistant import config_entries
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http import KEY_HASS, HomeAssistantView
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
Expand Down Expand Up @@ -348,7 +348,7 @@ async def post(self, request: web.Request) -> web.Response:
except ValueError:
return self.json_message("Invalid JSON", HTTPStatus.BAD_REQUEST)

hass: HomeAssistant = request.app["hass"]
hass = request.app[KEY_HASS]

data[ATTR_LAST_SEEN_AT] = datetime.datetime.now().isoformat()

Expand Down
9 changes: 5 additions & 4 deletions homeassistant/components/konnected/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from homeassistant import config_entries
from homeassistant.components.binary_sensor import DEVICE_CLASSES_SCHEMA
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http import KEY_HASS, HomeAssistantView
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_ENTITY_ID,
Expand Down Expand Up @@ -304,7 +304,7 @@ def binary_value(state, activation):

async def update_sensor(self, request: Request, device_id) -> Response:
"""Process a put or post."""
hass = request.app["hass"]
hass = request.app[KEY_HASS]
data = hass.data[DOMAIN]

auth = request.headers.get(AUTHORIZATION)
Expand Down Expand Up @@ -376,7 +376,7 @@ async def update_sensor(self, request: Request, device_id) -> Response:

async def get(self, request: Request, device_id) -> Response:
"""Return the current binary state of a switch."""
hass = request.app["hass"]
hass = request.app[KEY_HASS]
data = hass.data[DOMAIN]

if not (device := data[CONF_DEVICES].get(device_id)):
Expand Down Expand Up @@ -424,7 +424,8 @@ async def get(self, request: Request, device_id) -> Response:
# Make sure entity is setup
if zone_entity_id := zone.get(ATTR_ENTITY_ID):
resp["state"] = self.binary_value(
hass.states.get(zone_entity_id).state, zone[CONF_ACTIVATION]
hass.states.get(zone_entity_id).state, # type: ignore[union-attr]
zone[CONF_ACTIVATION],
)
return self.json(resp)

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/logbook/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from aiohttp import web
import voluptuous as vol

from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http import KEY_HASS, HomeAssistantView
from homeassistant.components.recorder import get_instance
from homeassistant.components.recorder.filters import Filters
from homeassistant.core import HomeAssistant, callback
Expand Down Expand Up @@ -86,7 +86,7 @@ async def get(
return self.json_message("Invalid end_time", HTTPStatus.BAD_REQUEST)
end_day = end_day_dt

hass = request.app["hass"]
hass = request.app[KEY_HASS]

context_id = request.query.get("context_id")

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/logi_circle/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from logi_circle.exception import AuthorizationFailed
import voluptuous as vol

from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http import KEY_HASS, HomeAssistantView
from homeassistant.config_entries import ConfigFlow
from homeassistant.const import (
CONF_API_KEY,
Expand Down Expand Up @@ -191,7 +191,7 @@ class LogiCircleAuthCallbackView(HomeAssistantView):

async def get(self, request):
"""Receive authorization code."""
hass = request.app["hass"]
hass = request.app[KEY_HASS]
if "code" in request.query:
hass.async_create_task(
hass.config_entries.flow.async_init(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/meraki/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
AsyncSeeCallback,
SourceType,
)
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http import KEY_HASS, HomeAssistantView
from homeassistant.core import HomeAssistant, callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
Expand Down Expand Up @@ -86,7 +86,7 @@ async def post(self, request):
if not data["data"]["observations"]:
_LOGGER.debug("No observations found")
return
self._handle(request.app["hass"], data)
self._handle(request.app[KEY_HASS], data)

@callback
def _handle(self, hass, data):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/mobile_app/http_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import voluptuous as vol

from homeassistant.components import cloud
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http import KEY_HASS, HomeAssistantView
from homeassistant.components.http.data_validator import RequestDataValidator
from homeassistant.const import ATTR_DEVICE_ID, CONF_WEBHOOK_ID
from homeassistant.helpers import config_validation as cv
Expand Down Expand Up @@ -65,7 +65,7 @@ class RegistrationsView(HomeAssistantView):
)
async def post(self, request: Request, data: dict) -> Response:
"""Handle the POST request for registration."""
hass = request.app["hass"]
hass = request.app[KEY_HASS]

webhook_id = secrets.token_hex()

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/mystrom/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging

from homeassistant.components.binary_sensor import DOMAIN, BinarySensorEntity
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http import KEY_HASS, HomeAssistantView
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
Expand Down Expand Up @@ -37,7 +37,7 @@ def __init__(self, add_entities):

async def get(self, request):
"""Handle the GET request received from a myStrom button."""
res = await self._handle(request.app["hass"], request.query)
res = await self._handle(request.app[KEY_HASS], request.query)
return res

async def _handle(self, hass, data):
Expand Down
14 changes: 7 additions & 7 deletions homeassistant/components/onboarding/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from homeassistant.auth.providers.homeassistant import HassAuthProvider
from homeassistant.components import person
from homeassistant.components.auth import indieauth
from homeassistant.components.http import KEY_HASS_REFRESH_TOKEN_ID
from homeassistant.components.http import KEY_HASS, KEY_HASS_REFRESH_TOKEN_ID
from homeassistant.components.http.data_validator import RequestDataValidator
from homeassistant.components.http.view import HomeAssistantView
from homeassistant.core import HomeAssistant, callback
Expand Down Expand Up @@ -85,7 +85,7 @@ async def get(self, request: web.Request) -> web.Response:
if self._data["done"]:
raise HTTPUnauthorized()

hass: HomeAssistant = request.app["hass"]
hass = request.app[KEY_HASS]
info = await async_get_system_info(hass)
return self.json({"installation_type": info["installation_type"]})

Expand Down Expand Up @@ -136,7 +136,7 @@ class UserOnboardingView(_BaseOnboardingView):
)
async def post(self, request: web.Request, data: dict[str, str]) -> web.Response:
"""Handle user creation, area creation."""
hass: HomeAssistant = request.app["hass"]
hass = request.app[KEY_HASS]

async with self._lock:
if self._async_is_done():
Expand Down Expand Up @@ -190,7 +190,7 @@ class CoreConfigOnboardingView(_BaseOnboardingView):

async def post(self, request: web.Request) -> web.Response:
"""Handle finishing core config step."""
hass: HomeAssistant = request.app["hass"]
hass = request.app[KEY_HASS]

async with self._lock:
if self._async_is_done():
Expand Down Expand Up @@ -250,7 +250,7 @@ class IntegrationOnboardingView(_BaseOnboardingView):
)
async def post(self, request: web.Request, data: dict[str, Any]) -> web.Response:
"""Handle token creation."""
hass: HomeAssistant = request.app["hass"]
hass = request.app[KEY_HASS]
refresh_token_id = request[KEY_HASS_REFRESH_TOKEN_ID]

async with self._lock:
Expand All @@ -263,7 +263,7 @@ async def post(self, request: web.Request, data: dict[str, Any]) -> web.Response

# Validate client ID and redirect uri
if not await indieauth.verify_redirect_uri(
request.app["hass"], data["client_id"], data["redirect_uri"]
request.app[KEY_HASS], data["client_id"], data["redirect_uri"]
):
return self.json_message(
"invalid client id or redirect uri", HTTPStatus.BAD_REQUEST
Expand Down Expand Up @@ -294,7 +294,7 @@ class AnalyticsOnboardingView(_BaseOnboardingView):

async def post(self, request: web.Request) -> web.Response:
"""Handle finishing analytics step."""
hass: HomeAssistant = request.app["hass"]
hass = request.app[KEY_HASS]

async with self._lock:
if self._async_is_done():
Expand Down