mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Attrs cleanups (#37849)
This commit is contained in:
parent
7e280e2b27
commit
ac0dbb17af
@ -77,10 +77,10 @@ def _verify_otp(secret: str, otp: str, count: int) -> bool:
|
|||||||
class NotifySetting:
|
class NotifySetting:
|
||||||
"""Store notify setting for one user."""
|
"""Store notify setting for one user."""
|
||||||
|
|
||||||
secret = attr.ib(type=str, factory=_generate_secret) # not persistent
|
secret: str = attr.ib(factory=_generate_secret) # not persistent
|
||||||
counter = attr.ib(type=int, factory=_generate_random) # not persistent
|
counter: int = attr.ib(factory=_generate_random) # not persistent
|
||||||
notify_service = attr.ib(type=Optional[str], default=None)
|
notify_service: Optional[str] = attr.ib(default=None)
|
||||||
target = attr.ib(type=Optional[str], default=None)
|
target: Optional[str] = attr.ib(default=None)
|
||||||
|
|
||||||
|
|
||||||
_UsersDict = Dict[str, NotifySetting]
|
_UsersDict = Dict[str, NotifySetting]
|
||||||
|
@ -20,39 +20,35 @@ TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN = "long_lived_access_token"
|
|||||||
class Group:
|
class Group:
|
||||||
"""A group."""
|
"""A group."""
|
||||||
|
|
||||||
name = attr.ib(type=Optional[str])
|
name: Optional[str] = attr.ib()
|
||||||
policy = attr.ib(type=perm_mdl.PolicyType)
|
policy: perm_mdl.PolicyType = attr.ib()
|
||||||
id = attr.ib(type=str, factory=lambda: uuid.uuid4().hex)
|
id: str = attr.ib(factory=lambda: uuid.uuid4().hex)
|
||||||
system_generated = attr.ib(type=bool, default=False)
|
system_generated: bool = attr.ib(default=False)
|
||||||
|
|
||||||
|
|
||||||
@attr.s(slots=True)
|
@attr.s(slots=True)
|
||||||
class User:
|
class User:
|
||||||
"""A user."""
|
"""A user."""
|
||||||
|
|
||||||
name = attr.ib(type=Optional[str])
|
name: Optional[str] = attr.ib()
|
||||||
perm_lookup = attr.ib(type=perm_mdl.PermissionLookup, eq=False, order=False)
|
perm_lookup: perm_mdl.PermissionLookup = attr.ib(eq=False, order=False)
|
||||||
id = attr.ib(type=str, factory=lambda: uuid.uuid4().hex)
|
id: str = attr.ib(factory=lambda: uuid.uuid4().hex)
|
||||||
is_owner = attr.ib(type=bool, default=False)
|
is_owner: bool = attr.ib(default=False)
|
||||||
is_active = attr.ib(type=bool, default=False)
|
is_active: bool = attr.ib(default=False)
|
||||||
system_generated = attr.ib(type=bool, default=False)
|
system_generated: bool = attr.ib(default=False)
|
||||||
|
|
||||||
groups = attr.ib(type=List[Group], factory=list, eq=False, order=False)
|
groups: List[Group] = attr.ib(factory=list, eq=False, order=False)
|
||||||
|
|
||||||
# List of credentials of a user.
|
# List of credentials of a user.
|
||||||
credentials = attr.ib(type=List["Credentials"], factory=list, eq=False, order=False)
|
credentials: List["Credentials"] = attr.ib(factory=list, eq=False, order=False)
|
||||||
|
|
||||||
# Tokens associated with a user.
|
# Tokens associated with a user.
|
||||||
refresh_tokens = attr.ib(
|
refresh_tokens: Dict[str, "RefreshToken"] = attr.ib(
|
||||||
type=Dict[str, "RefreshToken"], factory=dict, eq=False, order=False
|
factory=dict, eq=False, order=False
|
||||||
)
|
)
|
||||||
|
|
||||||
_permissions = attr.ib(
|
_permissions: Optional[perm_mdl.PolicyPermissions] = attr.ib(
|
||||||
type=Optional[perm_mdl.PolicyPermissions],
|
init=False, eq=False, order=False, default=None,
|
||||||
init=False,
|
|
||||||
eq=False,
|
|
||||||
order=False,
|
|
||||||
default=None,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -88,39 +84,38 @@ class User:
|
|||||||
class RefreshToken:
|
class RefreshToken:
|
||||||
"""RefreshToken for a user to grant new access tokens."""
|
"""RefreshToken for a user to grant new access tokens."""
|
||||||
|
|
||||||
user = attr.ib(type=User)
|
user: User = attr.ib()
|
||||||
client_id = attr.ib(type=Optional[str])
|
client_id: Optional[str] = attr.ib()
|
||||||
access_token_expiration = attr.ib(type=timedelta)
|
access_token_expiration: timedelta = attr.ib()
|
||||||
client_name = attr.ib(type=Optional[str], default=None)
|
client_name: Optional[str] = attr.ib(default=None)
|
||||||
client_icon = attr.ib(type=Optional[str], default=None)
|
client_icon: Optional[str] = attr.ib(default=None)
|
||||||
token_type = attr.ib(
|
token_type: str = attr.ib(
|
||||||
type=str,
|
|
||||||
default=TOKEN_TYPE_NORMAL,
|
default=TOKEN_TYPE_NORMAL,
|
||||||
validator=attr.validators.in_(
|
validator=attr.validators.in_(
|
||||||
(TOKEN_TYPE_NORMAL, TOKEN_TYPE_SYSTEM, TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN)
|
(TOKEN_TYPE_NORMAL, TOKEN_TYPE_SYSTEM, TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN)
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
id = attr.ib(type=str, factory=lambda: uuid.uuid4().hex)
|
id: str = attr.ib(factory=lambda: uuid.uuid4().hex)
|
||||||
created_at = attr.ib(type=datetime, factory=dt_util.utcnow)
|
created_at: datetime = attr.ib(factory=dt_util.utcnow)
|
||||||
token = attr.ib(type=str, factory=lambda: secrets.token_hex(64))
|
token: str = attr.ib(factory=lambda: secrets.token_hex(64))
|
||||||
jwt_key = attr.ib(type=str, factory=lambda: secrets.token_hex(64))
|
jwt_key: str = attr.ib(factory=lambda: secrets.token_hex(64))
|
||||||
|
|
||||||
last_used_at = attr.ib(type=Optional[datetime], default=None)
|
last_used_at: Optional[datetime] = attr.ib(default=None)
|
||||||
last_used_ip = attr.ib(type=Optional[str], default=None)
|
last_used_ip: Optional[str] = attr.ib(default=None)
|
||||||
|
|
||||||
|
|
||||||
@attr.s(slots=True)
|
@attr.s(slots=True)
|
||||||
class Credentials:
|
class Credentials:
|
||||||
"""Credentials for a user on an auth provider."""
|
"""Credentials for a user on an auth provider."""
|
||||||
|
|
||||||
auth_provider_type = attr.ib(type=str)
|
auth_provider_type: str = attr.ib()
|
||||||
auth_provider_id = attr.ib(type=Optional[str])
|
auth_provider_id: Optional[str] = attr.ib()
|
||||||
|
|
||||||
# Allow the auth provider to store data to represent their auth.
|
# Allow the auth provider to store data to represent their auth.
|
||||||
data = attr.ib(type=dict)
|
data: dict = attr.ib()
|
||||||
|
|
||||||
id = attr.ib(type=str, factory=lambda: uuid.uuid4().hex)
|
id: str = attr.ib(factory=lambda: uuid.uuid4().hex)
|
||||||
is_new = attr.ib(type=bool, default=True)
|
is_new: bool = attr.ib(default=True)
|
||||||
|
|
||||||
|
|
||||||
class UserMeta(NamedTuple):
|
class UserMeta(NamedTuple):
|
||||||
|
@ -13,5 +13,5 @@ if TYPE_CHECKING:
|
|||||||
class PermissionLookup:
|
class PermissionLookup:
|
||||||
"""Class to hold data for permission lookups."""
|
"""Class to hold data for permission lookups."""
|
||||||
|
|
||||||
entity_registry = attr.ib(type="ent_reg.EntityRegistry")
|
entity_registry: "ent_reg.EntityRegistry" = attr.ib()
|
||||||
device_registry = attr.ib(type="dev_reg.DeviceRegistry")
|
device_registry: "dev_reg.DeviceRegistry" = attr.ib()
|
||||||
|
@ -119,8 +119,8 @@ SCHEMA_WS_CAMERA_THUMBNAIL = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend(
|
|||||||
class Image:
|
class Image:
|
||||||
"""Represent an image."""
|
"""Represent an image."""
|
||||||
|
|
||||||
content_type = attr.ib(type=str)
|
content_type: str = attr.ib()
|
||||||
content = attr.ib(type=bytes)
|
content: bytes = attr.ib()
|
||||||
|
|
||||||
|
|
||||||
@bind_hass
|
@bind_hass
|
||||||
|
@ -14,14 +14,14 @@ class ChromecastInfo:
|
|||||||
This also has the same attributes as the mDNS fields by zeroconf.
|
This also has the same attributes as the mDNS fields by zeroconf.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
services = attr.ib(type=Optional[set])
|
services: Optional[set] = attr.ib()
|
||||||
host = attr.ib(type=Optional[str], default=None)
|
host: Optional[str] = attr.ib(default=None)
|
||||||
port = attr.ib(type=Optional[int], default=0)
|
port: Optional[int] = attr.ib(default=0)
|
||||||
uuid = attr.ib(
|
uuid: Optional[str] = attr.ib(
|
||||||
type=Optional[str], converter=attr.converters.optional(str), default=None
|
converter=attr.converters.optional(str), default=None
|
||||||
) # always convert UUID to string if not None
|
) # always convert UUID to string if not None
|
||||||
model_name = attr.ib(type=str, default="")
|
model_name: str = attr.ib(default="")
|
||||||
friendly_name = attr.ib(type=Optional[str], default=None)
|
friendly_name: Optional[str] = attr.ib(default=None)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_audio_group(self) -> bool:
|
def is_audio_group(self) -> bool:
|
||||||
|
@ -35,9 +35,9 @@ class DeviceTrackerPlatform:
|
|||||||
"setup_scanner",
|
"setup_scanner",
|
||||||
)
|
)
|
||||||
|
|
||||||
name = attr.ib(type=str)
|
name: str = attr.ib()
|
||||||
platform = attr.ib(type=ModuleType)
|
platform: ModuleType = attr.ib()
|
||||||
config = attr.ib(type=Dict)
|
config: Dict = attr.ib()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self):
|
def type(self):
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Runtime entry data for ESPHome stored in hass.data."""
|
"""Runtime entry data for ESPHome stored in hass.data."""
|
||||||
import asyncio
|
import asyncio
|
||||||
from typing import Any, Callable, Dict, List, Optional, Set, Tuple
|
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Set, Tuple
|
||||||
|
|
||||||
from aioesphomeapi import (
|
from aioesphomeapi import (
|
||||||
COMPONENT_TYPE_TO_INFO,
|
COMPONENT_TYPE_TO_INFO,
|
||||||
@ -26,6 +26,9 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
|
|||||||
from homeassistant.helpers.storage import Store
|
from homeassistant.helpers.storage import Store
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from . import APIClient
|
||||||
|
|
||||||
DATA_KEY = "esphome"
|
DATA_KEY = "esphome"
|
||||||
|
|
||||||
# Mapping from ESPHome info type to HA platform
|
# Mapping from ESPHome info type to HA platform
|
||||||
@ -46,26 +49,26 @@ INFO_TYPE_TO_PLATFORM = {
|
|||||||
class RuntimeEntryData:
|
class RuntimeEntryData:
|
||||||
"""Store runtime data for esphome config entries."""
|
"""Store runtime data for esphome config entries."""
|
||||||
|
|
||||||
entry_id = attr.ib(type=str)
|
entry_id: str = attr.ib()
|
||||||
client = attr.ib(type="APIClient")
|
client: "APIClient" = attr.ib()
|
||||||
store = attr.ib(type=Store)
|
store: Store = attr.ib()
|
||||||
reconnect_task = attr.ib(type=Optional[asyncio.Task], default=None)
|
reconnect_task: Optional[asyncio.Task] = attr.ib(default=None)
|
||||||
state = attr.ib(type=Dict[str, Dict[str, Any]], factory=dict)
|
state: Dict[str, Dict[str, Any]] = attr.ib(factory=dict)
|
||||||
info = attr.ib(type=Dict[str, Dict[str, Any]], factory=dict)
|
info: Dict[str, Dict[str, Any]] = attr.ib(factory=dict)
|
||||||
|
|
||||||
# A second list of EntityInfo objects
|
# A second list of EntityInfo objects
|
||||||
# This is necessary for when an entity is being removed. HA requires
|
# This is necessary for when an entity is being removed. HA requires
|
||||||
# some static info to be accessible during removal (unique_id, maybe others)
|
# some static info to be accessible during removal (unique_id, maybe others)
|
||||||
# If an entity can't find anything in the info array, it will look for info here.
|
# If an entity can't find anything in the info array, it will look for info here.
|
||||||
old_info = attr.ib(type=Dict[str, Dict[str, Any]], factory=dict)
|
old_info: Dict[str, Dict[str, Any]] = attr.ib(factory=dict)
|
||||||
|
|
||||||
services = attr.ib(type=Dict[int, "UserService"], factory=dict)
|
services: Dict[int, "UserService"] = attr.ib(factory=dict)
|
||||||
available = attr.ib(type=bool, default=False)
|
available: bool = attr.ib(default=False)
|
||||||
device_info = attr.ib(type=DeviceInfo, default=None)
|
device_info: Optional[DeviceInfo] = attr.ib(default=None)
|
||||||
cleanup_callbacks = attr.ib(type=List[Callable[[], None]], factory=list)
|
cleanup_callbacks: List[Callable[[], None]] = attr.ib(factory=list)
|
||||||
disconnect_callbacks = attr.ib(type=List[Callable[[], None]], factory=list)
|
disconnect_callbacks: List[Callable[[], None]] = attr.ib(factory=list)
|
||||||
loaded_platforms = attr.ib(type=Set[str], factory=set)
|
loaded_platforms: Set[str] = attr.ib(factory=set)
|
||||||
platform_load_lock = attr.ib(type=asyncio.Lock, factory=asyncio.Lock)
|
platform_load_lock: asyncio.Lock = attr.ib(factory=asyncio.Lock)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_update_entity(
|
def async_update_entity(
|
||||||
|
@ -612,10 +612,10 @@ async def async_setup_entry(hass, entry):
|
|||||||
class Subscription:
|
class Subscription:
|
||||||
"""Class to hold data about an active subscription."""
|
"""Class to hold data about an active subscription."""
|
||||||
|
|
||||||
topic = attr.ib(type=str)
|
topic: str = attr.ib()
|
||||||
callback = attr.ib(type=MessageCallbackType)
|
callback: MessageCallbackType = attr.ib()
|
||||||
qos = attr.ib(type=int, default=0)
|
qos: int = attr.ib(default=0)
|
||||||
encoding = attr.ib(type=str, default="utf-8")
|
encoding: str = attr.ib(default="utf-8")
|
||||||
|
|
||||||
|
|
||||||
class MQTT:
|
class MQTT:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Provides device automations for MQTT."""
|
"""Provides device automations for MQTT."""
|
||||||
import logging
|
import logging
|
||||||
from typing import Callable, List
|
from typing import Callable, List, Optional
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -75,10 +75,10 @@ DEVICE_TRIGGERS = "mqtt_device_triggers"
|
|||||||
class TriggerInstance:
|
class TriggerInstance:
|
||||||
"""Attached trigger settings."""
|
"""Attached trigger settings."""
|
||||||
|
|
||||||
action = attr.ib(type=AutomationActionType)
|
action: AutomationActionType = attr.ib()
|
||||||
automation_info = attr.ib(type=dict)
|
automation_info: dict = attr.ib()
|
||||||
trigger = attr.ib(type="Trigger")
|
trigger: "Trigger" = attr.ib()
|
||||||
remove = attr.ib(type=CALLBACK_TYPE, default=None)
|
remove: Optional[CALLBACK_TYPE] = attr.ib(default=None)
|
||||||
|
|
||||||
async def async_attach_trigger(self):
|
async def async_attach_trigger(self):
|
||||||
"""Attach MQTT trigger."""
|
"""Attach MQTT trigger."""
|
||||||
@ -101,16 +101,16 @@ class TriggerInstance:
|
|||||||
class Trigger:
|
class Trigger:
|
||||||
"""Device trigger settings."""
|
"""Device trigger settings."""
|
||||||
|
|
||||||
device_id = attr.ib(type=str)
|
device_id: str = attr.ib()
|
||||||
discovery_data = attr.ib(type=dict)
|
discovery_data: dict = attr.ib()
|
||||||
hass = attr.ib(type=HomeAssistantType)
|
hass: HomeAssistantType = attr.ib()
|
||||||
payload = attr.ib(type=str)
|
payload: str = attr.ib()
|
||||||
qos = attr.ib(type=int)
|
qos: int = attr.ib()
|
||||||
remove_signal = attr.ib(type=Callable[[], None])
|
remove_signal: Callable[[], None] = attr.ib()
|
||||||
subtype = attr.ib(type=str)
|
subtype: str = attr.ib()
|
||||||
topic = attr.ib(type=str)
|
topic: str = attr.ib()
|
||||||
type = attr.ib(type=str)
|
type: str = attr.ib()
|
||||||
trigger_instances = attr.ib(type=[TriggerInstance], default=attr.Factory(list))
|
trigger_instances: List[TriggerInstance] = attr.ib(factory=list)
|
||||||
|
|
||||||
async def add_trigger(self, action, automation_info):
|
async def add_trigger(self, action, automation_info):
|
||||||
"""Add MQTT trigger."""
|
"""Add MQTT trigger."""
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Modesl used by multiple MQTT modules."""
|
"""Modesl used by multiple MQTT modules."""
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
from typing import Callable, Union
|
from typing import Callable, Optional, Union
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
|
|
||||||
@ -11,12 +11,12 @@ PublishPayloadType = Union[str, bytes, int, float, None]
|
|||||||
class Message:
|
class Message:
|
||||||
"""MQTT Message."""
|
"""MQTT Message."""
|
||||||
|
|
||||||
topic = attr.ib(type=str)
|
topic: str = attr.ib()
|
||||||
payload = attr.ib(type=PublishPayloadType)
|
payload: PublishPayloadType = attr.ib()
|
||||||
qos = attr.ib(type=int)
|
qos: int = attr.ib()
|
||||||
retain = attr.ib(type=bool)
|
retain: bool = attr.ib()
|
||||||
subscribed_topic = attr.ib(type=str, default=None)
|
subscribed_topic: Optional[str] = attr.ib(default=None)
|
||||||
timestamp = attr.ib(type=dt.datetime, default=None)
|
timestamp: Optional[dt.datetime] = attr.ib(default=None)
|
||||||
|
|
||||||
|
|
||||||
MessageCallbackType = Callable[[Message], None]
|
MessageCallbackType = Callable[[Message], None]
|
||||||
|
@ -19,12 +19,12 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
class EntitySubscription:
|
class EntitySubscription:
|
||||||
"""Class to hold data about an active entity topic subscription."""
|
"""Class to hold data about an active entity topic subscription."""
|
||||||
|
|
||||||
hass = attr.ib(type=HomeAssistantType)
|
hass: HomeAssistantType = attr.ib()
|
||||||
topic = attr.ib(type=str)
|
topic: str = attr.ib()
|
||||||
message_callback = attr.ib(type=MessageCallbackType)
|
message_callback: MessageCallbackType = attr.ib()
|
||||||
unsubscribe_callback = attr.ib(type=Optional[Callable[[], None]])
|
unsubscribe_callback: Optional[Callable[[], None]] = attr.ib()
|
||||||
qos = attr.ib(type=int, default=0)
|
qos: int = attr.ib(default=0)
|
||||||
encoding = attr.ib(type=str, default="utf-8")
|
encoding: str = attr.ib(default="utf-8")
|
||||||
|
|
||||||
async def resubscribe_if_necessary(self, hass, other):
|
async def resubscribe_if_necessary(self, hass, other):
|
||||||
"""Re-subscribe to the new topic if necessary."""
|
"""Re-subscribe to the new topic if necessary."""
|
||||||
|
@ -21,19 +21,19 @@ PROVIDERS = Registry()
|
|||||||
class StreamBuffer:
|
class StreamBuffer:
|
||||||
"""Represent a segment."""
|
"""Represent a segment."""
|
||||||
|
|
||||||
segment = attr.ib(type=io.BytesIO)
|
segment: io.BytesIO = attr.ib()
|
||||||
output = attr.ib() # type=av.OutputContainer
|
output = attr.ib() # type=av.OutputContainer
|
||||||
vstream = attr.ib() # type=av.VideoStream
|
vstream = attr.ib() # type=av.VideoStream
|
||||||
astream = attr.ib(default=None) # type=av.AudioStream
|
astream = attr.ib(default=None) # type=Optional[av.AudioStream]
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class Segment:
|
class Segment:
|
||||||
"""Represent a segment."""
|
"""Represent a segment."""
|
||||||
|
|
||||||
sequence = attr.ib(type=int)
|
sequence: int = attr.ib()
|
||||||
segment = attr.ib(type=io.BytesIO)
|
segment: io.BytesIO = attr.ib()
|
||||||
duration = attr.ib(type=float)
|
duration: float = attr.ib()
|
||||||
|
|
||||||
|
|
||||||
class StreamOutput:
|
class StreamOutput:
|
||||||
|
@ -4,7 +4,7 @@ from collections import OrderedDict
|
|||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from typing import MutableMapping, cast
|
from typing import MutableMapping, Optional, cast
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
|
|
||||||
@ -28,9 +28,9 @@ TOMBSTONE_LIFETIME = datetime.timedelta(days=60).total_seconds()
|
|||||||
class ZhaDeviceEntry:
|
class ZhaDeviceEntry:
|
||||||
"""Zha Device storage Entry."""
|
"""Zha Device storage Entry."""
|
||||||
|
|
||||||
name = attr.ib(type=str, default=None)
|
name: Optional[str] = attr.ib(default=None)
|
||||||
ieee = attr.ib(type=str, default=None)
|
ieee: Optional[str] = attr.ib(default=None)
|
||||||
last_seen = attr.ib(type=float, default=None)
|
last_seen: Optional[float] = attr.ib(default=None)
|
||||||
|
|
||||||
|
|
||||||
class ZhaStorage:
|
class ZhaStorage:
|
||||||
|
@ -1025,7 +1025,7 @@ class OptionsFlow(data_entry_flow.FlowHandler):
|
|||||||
class SystemOptions:
|
class SystemOptions:
|
||||||
"""Config entry system options."""
|
"""Config entry system options."""
|
||||||
|
|
||||||
disable_new_entities = attr.ib(type=bool, default=False)
|
disable_new_entities: bool = attr.ib(default=False)
|
||||||
|
|
||||||
def update(self, *, disable_new_entities: bool) -> None:
|
def update(self, *, disable_new_entities: bool) -> None:
|
||||||
"""Update properties."""
|
"""Update properties."""
|
||||||
|
@ -456,9 +456,9 @@ class HomeAssistant:
|
|||||||
class Context:
|
class Context:
|
||||||
"""The context that triggered something."""
|
"""The context that triggered something."""
|
||||||
|
|
||||||
user_id = attr.ib(type=str, default=None)
|
user_id: str = attr.ib(default=None)
|
||||||
parent_id = attr.ib(type=Optional[str], default=None)
|
parent_id: Optional[str] = attr.ib(default=None)
|
||||||
id = attr.ib(type=str, default=attr.Factory(lambda: uuid.uuid4().hex))
|
id: str = attr.ib(factory=lambda: uuid.uuid4().hex)
|
||||||
|
|
||||||
def as_dict(self) -> dict:
|
def as_dict(self) -> dict:
|
||||||
"""Return a dictionary representation of the context."""
|
"""Return a dictionary representation of the context."""
|
||||||
|
@ -25,8 +25,8 @@ SAVE_DELAY = 10
|
|||||||
class AreaEntry:
|
class AreaEntry:
|
||||||
"""Area Registry Entry."""
|
"""Area Registry Entry."""
|
||||||
|
|
||||||
name = attr.ib(type=str, default=None)
|
name: Optional[str] = attr.ib(default=None)
|
||||||
id = attr.ib(type=str, default=attr.Factory(lambda: uuid.uuid4().hex))
|
id: str = attr.ib(factory=lambda: uuid.uuid4().hex)
|
||||||
|
|
||||||
|
|
||||||
class AreaRegistry:
|
class AreaRegistry:
|
||||||
|
@ -40,7 +40,7 @@ class CheckConfigError(NamedTuple):
|
|||||||
class HomeAssistantConfig(OrderedDict):
|
class HomeAssistantConfig(OrderedDict):
|
||||||
"""Configuration result with errors attribute."""
|
"""Configuration result with errors attribute."""
|
||||||
|
|
||||||
errors: List[CheckConfigError] = attr.ib(default=attr.Factory(list))
|
errors: List[CheckConfigError] = attr.ib(factory=list)
|
||||||
|
|
||||||
def add_error(
|
def add_error(
|
||||||
self,
|
self,
|
||||||
|
@ -57,13 +57,9 @@ class DeletedDeviceEntry:
|
|||||||
class DeviceEntry:
|
class DeviceEntry:
|
||||||
"""Device Registry Entry."""
|
"""Device Registry Entry."""
|
||||||
|
|
||||||
config_entries: Set[str] = attr.ib(converter=set, default=attr.Factory(set))
|
config_entries: Set[str] = attr.ib(converter=set, factory=set)
|
||||||
connections: Set[Tuple[str, str]] = attr.ib(
|
connections: Set[Tuple[str, str]] = attr.ib(converter=set, factory=set)
|
||||||
converter=set, default=attr.Factory(set)
|
identifiers: Set[Tuple[str, str]] = attr.ib(converter=set, factory=set)
|
||||||
)
|
|
||||||
identifiers: Set[Tuple[str, str]] = attr.ib(
|
|
||||||
converter=set, default=attr.Factory(set)
|
|
||||||
)
|
|
||||||
manufacturer: str = attr.ib(default=None)
|
manufacturer: str = attr.ib(default=None)
|
||||||
model: str = attr.ib(default=None)
|
model: str = attr.ib(default=None)
|
||||||
name: str = attr.ib(default=None)
|
name: str = attr.ib(default=None)
|
||||||
@ -72,7 +68,7 @@ class DeviceEntry:
|
|||||||
area_id: str = attr.ib(default=None)
|
area_id: str = attr.ib(default=None)
|
||||||
name_by_user: str = attr.ib(default=None)
|
name_by_user: str = attr.ib(default=None)
|
||||||
entry_type: str = attr.ib(default=None)
|
entry_type: str = attr.ib(default=None)
|
||||||
id: str = attr.ib(default=attr.Factory(lambda: uuid.uuid4().hex))
|
id: str = attr.ib(factory=lambda: uuid.uuid4().hex)
|
||||||
# This value is not stored, just used to keep track of events to fire.
|
# This value is not stored, just used to keep track of events to fire.
|
||||||
is_new: bool = attr.ib(default=False)
|
is_new: bool = attr.ib(default=False)
|
||||||
|
|
||||||
|
@ -78,15 +78,14 @@ ENTITY_DESCRIBING_ATTRIBUTES = {
|
|||||||
class RegistryEntry:
|
class RegistryEntry:
|
||||||
"""Entity Registry Entry."""
|
"""Entity Registry Entry."""
|
||||||
|
|
||||||
entity_id = attr.ib(type=str)
|
entity_id: str = attr.ib()
|
||||||
unique_id = attr.ib(type=str)
|
unique_id: str = attr.ib()
|
||||||
platform = attr.ib(type=str)
|
platform: str = attr.ib()
|
||||||
name = attr.ib(type=str, default=None)
|
name: Optional[str] = attr.ib(default=None)
|
||||||
icon = attr.ib(type=str, default=None)
|
icon: Optional[str] = attr.ib(default=None)
|
||||||
device_id: Optional[str] = attr.ib(default=None)
|
device_id: Optional[str] = attr.ib(default=None)
|
||||||
config_entry_id: Optional[str] = attr.ib(default=None)
|
config_entry_id: Optional[str] = attr.ib(default=None)
|
||||||
disabled_by = attr.ib(
|
disabled_by: Optional[str] = attr.ib(
|
||||||
type=Optional[str],
|
|
||||||
default=None,
|
default=None,
|
||||||
validator=attr.validators.in_(
|
validator=attr.validators.in_(
|
||||||
(
|
(
|
||||||
@ -105,7 +104,7 @@ class RegistryEntry:
|
|||||||
# As set by integration
|
# As set by integration
|
||||||
original_name: Optional[str] = attr.ib(default=None)
|
original_name: Optional[str] = attr.ib(default=None)
|
||||||
original_icon: Optional[str] = attr.ib(default=None)
|
original_icon: Optional[str] = attr.ib(default=None)
|
||||||
domain = attr.ib(type=str, init=False, repr=False)
|
domain: str = attr.ib(init=False, repr=False)
|
||||||
|
|
||||||
@domain.default
|
@domain.default
|
||||||
def _domain_default(self) -> str:
|
def _domain_default(self) -> str:
|
||||||
|
@ -400,7 +400,7 @@ track_time_interval = threaded_listener_factory(async_track_time_interval)
|
|||||||
class SunListener:
|
class SunListener:
|
||||||
"""Helper class to help listen to sun events."""
|
"""Helper class to help listen to sun events."""
|
||||||
|
|
||||||
hass = attr.ib(type=HomeAssistant)
|
hass: HomeAssistant = attr.ib()
|
||||||
action: Callable[..., None] = attr.ib()
|
action: Callable[..., None] = attr.ib()
|
||||||
event: str = attr.ib()
|
event: str = attr.ib()
|
||||||
offset: Optional[timedelta] = attr.ib()
|
offset: Optional[timedelta] = attr.ib()
|
||||||
|
@ -167,8 +167,8 @@ COLORS = {
|
|||||||
class XYPoint:
|
class XYPoint:
|
||||||
"""Represents a CIE 1931 XY coordinate pair."""
|
"""Represents a CIE 1931 XY coordinate pair."""
|
||||||
|
|
||||||
x = attr.ib(type=float) # pylint: disable=invalid-name
|
x: float = attr.ib() # pylint: disable=invalid-name
|
||||||
y = attr.ib(type=float) # pylint: disable=invalid-name
|
y: float = attr.ib() # pylint: disable=invalid-name
|
||||||
|
|
||||||
|
|
||||||
@attr.s()
|
@attr.s()
|
||||||
@ -176,9 +176,9 @@ class GamutType:
|
|||||||
"""Represents the Gamut of a light."""
|
"""Represents the Gamut of a light."""
|
||||||
|
|
||||||
# ColorGamut = gamut(xypoint(xR,yR),xypoint(xG,yG),xypoint(xB,yB))
|
# ColorGamut = gamut(xypoint(xR,yR),xypoint(xG,yG),xypoint(xB,yB))
|
||||||
red = attr.ib(type=XYPoint)
|
red: XYPoint = attr.ib()
|
||||||
green = attr.ib(type=XYPoint)
|
green: XYPoint = attr.ib()
|
||||||
blue = attr.ib(type=XYPoint)
|
blue: XYPoint = attr.ib()
|
||||||
|
|
||||||
|
|
||||||
def color_name_to_rgb(color_name: str) -> Tuple[int, int, int]:
|
def color_name_to_rgb(color_name: str) -> Tuple[int, int, int]:
|
||||||
|
@ -11,9 +11,9 @@ import attr
|
|||||||
class Error:
|
class Error:
|
||||||
"""Error validating an integration."""
|
"""Error validating an integration."""
|
||||||
|
|
||||||
plugin = attr.ib(type=str)
|
plugin: str = attr.ib()
|
||||||
error = attr.ib(type=str)
|
error: str = attr.ib()
|
||||||
fixable = attr.ib(type=bool, default=False)
|
fixable: bool = attr.ib(default=False)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
"""Represent error as string."""
|
"""Represent error as string."""
|
||||||
@ -63,10 +63,10 @@ class Integration:
|
|||||||
|
|
||||||
return integrations
|
return integrations
|
||||||
|
|
||||||
path = attr.ib(type=pathlib.Path)
|
path: pathlib.Path = attr.ib()
|
||||||
manifest = attr.ib(type=dict, default=None)
|
manifest: Optional[dict] = attr.ib(default=None)
|
||||||
errors = attr.ib(type=List[Error], factory=list)
|
errors: List[Error] = attr.ib(factory=list)
|
||||||
warnings = attr.ib(type=List[Error], factory=list)
|
warnings: List[Error] = attr.ib(factory=list)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def domain(self) -> str:
|
def domain(self) -> str:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user