Move slack base entity to separate module (#126175)
This commit is contained in:
parent
fdf460b82b
commit
bbe64e99e1
3 changed files with 37 additions and 29 deletions
|
@ -13,8 +13,6 @@ from homeassistant.const import CONF_API_KEY, Platform
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import aiohttp_client, config_validation as cv, discovery
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
|
@ -22,7 +20,6 @@ from .const import (
|
|||
ATTR_USER_ID,
|
||||
DATA_CLIENT,
|
||||
DATA_HASS_CONFIG,
|
||||
DEFAULT_NAME,
|
||||
DOMAIN,
|
||||
SLACK_DATA,
|
||||
)
|
||||
|
@ -74,28 +71,3 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class SlackEntity(Entity):
|
||||
"""Representation of a Slack entity."""
|
||||
|
||||
_attr_attribution = "Data provided by Slack"
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
data: dict[str, str | WebClient],
|
||||
description: EntityDescription,
|
||||
entry: ConfigEntry,
|
||||
) -> None:
|
||||
"""Initialize a Slack entity."""
|
||||
self._client = data[DATA_CLIENT]
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = f"{data[ATTR_USER_ID]}_{description.key}"
|
||||
self._attr_device_info = DeviceInfo(
|
||||
configuration_url=data[ATTR_URL],
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
identifiers={(DOMAIN, entry.entry_id)},
|
||||
manufacturer=DEFAULT_NAME,
|
||||
name=entry.title,
|
||||
)
|
||||
|
|
36
homeassistant/components/slack/entity.py
Normal file
36
homeassistant/components/slack/entity.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
"""The slack integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from slack import WebClient
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||
|
||||
from .const import ATTR_URL, ATTR_USER_ID, DATA_CLIENT, DEFAULT_NAME, DOMAIN
|
||||
|
||||
|
||||
class SlackEntity(Entity):
|
||||
"""Representation of a Slack entity."""
|
||||
|
||||
_attr_attribution = "Data provided by Slack"
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
data: dict[str, str | WebClient],
|
||||
description: EntityDescription,
|
||||
entry: ConfigEntry,
|
||||
) -> None:
|
||||
"""Initialize a Slack entity."""
|
||||
self._client = data[DATA_CLIENT]
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = f"{data[ATTR_USER_ID]}_{description.key}"
|
||||
self._attr_device_info = DeviceInfo(
|
||||
configuration_url=data[ATTR_URL],
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
identifiers={(DOMAIN, entry.entry_id)},
|
||||
manufacturer=DEFAULT_NAME,
|
||||
name=entry.title,
|
||||
)
|
|
@ -14,8 +14,8 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from . import SlackEntity
|
||||
from .const import ATTR_SNOOZE, DOMAIN, SLACK_DATA
|
||||
from .entity import SlackEntity
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
|
Loading…
Add table
Reference in a new issue