Add basic type hints to utility_meter ()

Co-authored-by: Diogo Gomes <diogogomes@gmail.com>
pull/69350/head
epenet 2022-04-05 15:43:10 +02:00 committed by GitHub
parent 28350b9792
commit 2cf3057ff1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions
homeassistant/components/utility_meter
tests/components/utility_meter

View File

@ -20,6 +20,7 @@ from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .const import (
ATTR_TARIFF,
@ -50,8 +51,20 @@ async def async_setup_entry(
async_add_entities([tariff_select])
async def async_setup_platform(hass, conf, async_add_entities, discovery_info=None):
async def async_setup_platform(
hass: HomeAssistant,
conf: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the utility meter select."""
if discovery_info is None:
_LOGGER.error(
"This platform is not available to configure "
"from 'select:' in configuration.yaml"
)
return
legacy_component = hass.data[DATA_LEGACY_COMPONENT]
async_add_entities(
[

View File

@ -176,7 +176,10 @@ async def async_setup_platform(
) -> None:
"""Set up the utility meter sensor."""
if discovery_info is None:
_LOGGER.error("This platform is only available through discovery")
_LOGGER.error(
"This platform is not available to configure "
"from 'sensor:' in configuration.yaml"
)
return
meters = []

View File

@ -17,6 +17,7 @@ from homeassistant.components.utility_meter.const import (
SERVICE_SELECT_TARIFF,
SIGNAL_RESET_METER,
)
import homeassistant.components.utility_meter.select as um_select
import homeassistant.components.utility_meter.sensor as um_sensor
from homeassistant.const import (
ATTR_ENTITY_ID,
@ -380,6 +381,7 @@ async def test_bad_cron(hass, legacy_patchable_time):
async def test_setup_missing_discovery(hass):
"""Test setup with configuration missing discovery_info."""
assert not await um_select.async_setup_platform(hass, {CONF_PLATFORM: DOMAIN}, None)
assert not await um_sensor.async_setup_platform(hass, {CONF_PLATFORM: DOMAIN}, None)