Explicitely allow Platform enum in discovery helper (#63571)

* Adjust Platform type hint in discovery helper

* Adjust amcrest

* Adjust comfoconnect

* Adjust ecovacs

* Adjust egardia

* Rename arguments

* Convert Platform enum to string explicitely

* Revert "Adjust egardia"

This reverts commit ff7b0d6100.

* Revert "Adjust ecovacs"

This reverts commit 2749045e13.

* Revert "Adjust comfoconnect"

This reverts commit bfff08f7fc.

* Undo argument name change and conversion to string

* Remove comment

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/63577/head
epenet 2022-01-09 06:06:56 +01:00 committed by GitHub
parent 89859aad8d
commit 665eeb4b27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 10 deletions

View File

@ -15,10 +15,6 @@ import voluptuous as vol
from homeassistant.auth.models import User from homeassistant.auth.models import User
from homeassistant.auth.permissions.const import POLICY_CONTROL from homeassistant.auth.permissions.const import POLICY_CONTROL
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR
from homeassistant.components.camera import DOMAIN as CAMERA
from homeassistant.components.sensor import DOMAIN as SENSOR
from homeassistant.components.switch import DOMAIN as SWITCH
from homeassistant.const import ( from homeassistant.const import (
ATTR_ENTITY_ID, ATTR_ENTITY_ID,
CONF_AUTHENTICATION, CONF_AUTHENTICATION,
@ -34,6 +30,7 @@ from homeassistant.const import (
ENTITY_MATCH_ALL, ENTITY_MATCH_ALL,
ENTITY_MATCH_NONE, ENTITY_MATCH_NONE,
HTTP_BASIC_AUTHENTICATION, HTTP_BASIC_AUTHENTICATION,
Platform,
) )
from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.exceptions import Unauthorized, UnknownUser from homeassistant.exceptions import Unauthorized, UnknownUser
@ -301,13 +298,15 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
control_light, control_light,
) )
discovery.load_platform(hass, CAMERA, DOMAIN, {CONF_NAME: name}, config) discovery.load_platform(
hass, Platform.CAMERA, DOMAIN, {CONF_NAME: name}, config
)
event_codes = set() event_codes = set()
if binary_sensors: if binary_sensors:
discovery.load_platform( discovery.load_platform(
hass, hass,
BINARY_SENSOR, Platform.BINARY_SENSOR,
DOMAIN, DOMAIN,
{CONF_NAME: name, CONF_BINARY_SENSORS: binary_sensors}, {CONF_NAME: name, CONF_BINARY_SENSORS: binary_sensors},
config, config,
@ -324,12 +323,20 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
if sensors: if sensors:
discovery.load_platform( discovery.load_platform(
hass, SENSOR, DOMAIN, {CONF_NAME: name, CONF_SENSORS: sensors}, config hass,
Platform.SENSOR,
DOMAIN,
{CONF_NAME: name, CONF_SENSORS: sensors},
config,
) )
if switches: if switches:
discovery.load_platform( discovery.load_platform(
hass, SWITCH, DOMAIN, {CONF_NAME: name, CONF_SWITCHES: switches}, config hass,
Platform.SWITCH,
DOMAIN,
{CONF_NAME: name, CONF_SWITCHES: switches},
config,
) )
if not hass.data[DATA_AMCREST][DEVICES]: if not hass.data[DATA_AMCREST][DEVICES]:

View File

@ -11,6 +11,7 @@ from collections.abc import Callable
from typing import Any, TypedDict from typing import Any, TypedDict
from homeassistant import core, setup from homeassistant import core, setup
from homeassistant.const import Platform
from homeassistant.core import CALLBACK_TYPE from homeassistant.core import CALLBACK_TYPE
from homeassistant.loader import bind_hass from homeassistant.loader import bind_hass
@ -126,7 +127,7 @@ def async_listen_platform(
@bind_hass @bind_hass
def load_platform( def load_platform(
hass: core.HomeAssistant, hass: core.HomeAssistant,
component: str, component: Platform | str,
platform: str, platform: str,
discovered: DiscoveryInfoType, discovered: DiscoveryInfoType,
hass_config: ConfigType, hass_config: ConfigType,
@ -142,7 +143,7 @@ def load_platform(
@bind_hass @bind_hass
async def async_load_platform( async def async_load_platform(
hass: core.HomeAssistant, hass: core.HomeAssistant,
component: str, component: Platform | str,
platform: str, platform: str,
discovered: DiscoveryInfoType, discovered: DiscoveryInfoType,
hass_config: ConfigType, hass_config: ConfigType,