Add basic type hints to command_line (#62877)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/62963/head
epenet 2021-12-28 21:56:38 +01:00 committed by GitHub
parent 8b59b3baf4
commit 4f32a329a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 6 deletions

View File

@ -1,4 +1,6 @@
"""Support for custom shell commands to retrieve values."""
from __future__ import annotations
from datetime import timedelta
import voluptuous as vol
@ -16,8 +18,11 @@ from homeassistant.const import (
CONF_PAYLOAD_ON,
CONF_VALUE_TEMPLATE,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.reload import setup_reload_service
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .const import CONF_COMMAND_TIMEOUT, DEFAULT_TIMEOUT, DOMAIN, PLATFORMS
from .sensor import CommandSensorData
@ -42,7 +47,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
)
def setup_platform(hass, config, add_entities, discovery_info=None):
def setup_platform(
hass: HomeAssistant,
config: ConfigType,
add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the Command line Binary Sensor."""
setup_reload_service(hass, DOMAIN, PLATFORMS)

View File

@ -1,4 +1,6 @@
"""Support for command line covers."""
from __future__ import annotations
import logging
import voluptuous as vol
@ -13,8 +15,11 @@ from homeassistant.const import (
CONF_FRIENDLY_NAME,
CONF_VALUE_TEMPLATE,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.reload import setup_reload_service
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import call_shell_with_timeout, check_output_or_log
from .const import CONF_COMMAND_TIMEOUT, DEFAULT_TIMEOUT, DOMAIN, PLATFORMS
@ -38,7 +43,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
)
def setup_platform(hass, config, add_entities, discovery_info=None):
def setup_platform(
hass: HomeAssistant,
config: ConfigType,
add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up cover controlled by shell commands."""
setup_reload_service(hass, DOMAIN, PLATFORMS)
@ -66,7 +76,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
if not covers:
_LOGGER.error("No covers added")
return False
return
add_entities(covers)

View File

@ -1,4 +1,6 @@
"""Allows to configure custom shell commands to turn a value for a sensor."""
from __future__ import annotations
from collections.abc import Mapping
from datetime import timedelta
import json
@ -14,10 +16,13 @@ from homeassistant.const import (
CONF_VALUE_TEMPLATE,
STATE_UNKNOWN,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import TemplateError
from homeassistant.helpers import template
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.reload import setup_reload_service
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import check_output_or_log
from .const import CONF_COMMAND_TIMEOUT, DEFAULT_TIMEOUT, DOMAIN, PLATFORMS
@ -42,7 +47,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
)
def setup_platform(hass, config, add_entities, discovery_info=None):
def setup_platform(
hass: HomeAssistant,
config: ConfigType,
add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the Command Sensor."""
setup_reload_service(hass, DOMAIN, PLATFORMS)

View File

@ -1,4 +1,6 @@
"""Support for custom shell commands to turn a switch on/off."""
from __future__ import annotations
import logging
import voluptuous as vol
@ -17,8 +19,11 @@ from homeassistant.const import (
CONF_SWITCHES,
CONF_VALUE_TEMPLATE,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.reload import setup_reload_service
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import call_shell_with_timeout, check_output_or_log
from .const import CONF_COMMAND_TIMEOUT, DEFAULT_TIMEOUT, DOMAIN, PLATFORMS
@ -42,7 +47,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
)
def setup_platform(hass, config, add_entities, discovery_info=None):
def setup_platform(
hass: HomeAssistant,
config: ConfigType,
add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Find and return switches controlled by shell commands."""
setup_reload_service(hass, DOMAIN, PLATFORMS)
@ -76,7 +86,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
if not switches:
_LOGGER.error("No switches added")
return False
return
add_entities(switches)