mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 02:37:08 +00:00
Move nextbus constants and utils (#92211)
* NextBus: Move general components to const and util * Remove not yet used code
This commit is contained in:
parent
aee3f115d6
commit
0fcf8f968b
6
homeassistant/components/nextbus/const.py
Normal file
6
homeassistant/components/nextbus/const.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
"""NextBus Constants."""
|
||||||
|
DOMAIN = "nextbus"
|
||||||
|
|
||||||
|
CONF_AGENCY = "agency"
|
||||||
|
CONF_ROUTE = "route"
|
||||||
|
CONF_STOP = "stop"
|
@ -19,14 +19,11 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
from homeassistant.util.dt import utc_from_timestamp
|
from homeassistant.util.dt import utc_from_timestamp
|
||||||
|
|
||||||
|
from .const import CONF_AGENCY, CONF_ROUTE, CONF_STOP
|
||||||
|
from .util import listify, maybe_first
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DOMAIN = "nextbus"
|
|
||||||
|
|
||||||
CONF_AGENCY = "agency"
|
|
||||||
CONF_ROUTE = "route"
|
|
||||||
CONF_STOP = "stop"
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_AGENCY): cv.string,
|
vol.Required(CONF_AGENCY): cv.string,
|
||||||
@ -37,29 +34,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def listify(maybe_list):
|
|
||||||
"""Return list version of whatever value is passed in.
|
|
||||||
|
|
||||||
This is used to provide a consistent way of interacting with the JSON
|
|
||||||
results from the API. There are several attributes that will either missing
|
|
||||||
if there are no values, a single dictionary if there is only one value, and
|
|
||||||
a list if there are multiple.
|
|
||||||
"""
|
|
||||||
if maybe_list is None:
|
|
||||||
return []
|
|
||||||
if isinstance(maybe_list, list):
|
|
||||||
return maybe_list
|
|
||||||
return [maybe_list]
|
|
||||||
|
|
||||||
|
|
||||||
def maybe_first(maybe_list):
|
|
||||||
"""Return the first item out of a list or returns back the input."""
|
|
||||||
if isinstance(maybe_list, list) and maybe_list:
|
|
||||||
return maybe_list[0]
|
|
||||||
|
|
||||||
return maybe_list
|
|
||||||
|
|
||||||
|
|
||||||
def validate_value(value_name, value, value_list):
|
def validate_value(value_name, value, value_list):
|
||||||
"""Validate tag value is in the list of items and logs error if not."""
|
"""Validate tag value is in the list of items and logs error if not."""
|
||||||
valid_values = {v["tag"]: v["title"] for v in value_list}
|
valid_values = {v["tag"]: v["title"] for v in value_list}
|
||||||
|
25
homeassistant/components/nextbus/util.py
Normal file
25
homeassistant/components/nextbus/util.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
"""Utils for NextBus integration module."""
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
def listify(maybe_list: Any) -> list[Any]:
|
||||||
|
"""Return list version of whatever value is passed in.
|
||||||
|
|
||||||
|
This is used to provide a consistent way of interacting with the JSON
|
||||||
|
results from the API. There are several attributes that will either missing
|
||||||
|
if there are no values, a single dictionary if there is only one value, and
|
||||||
|
a list if there are multiple.
|
||||||
|
"""
|
||||||
|
if maybe_list is None:
|
||||||
|
return []
|
||||||
|
if isinstance(maybe_list, list):
|
||||||
|
return maybe_list
|
||||||
|
return [maybe_list]
|
||||||
|
|
||||||
|
|
||||||
|
def maybe_first(maybe_list: list[Any]) -> Any:
|
||||||
|
"""Return the first item out of a list or returns back the input."""
|
||||||
|
if isinstance(maybe_list, list) and maybe_list:
|
||||||
|
return maybe_list[0]
|
||||||
|
|
||||||
|
return maybe_list
|
Loading…
x
Reference in New Issue
Block a user