1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-22 03:49:36 +00:00
Files
core/homeassistant/components/slack/entity.py
jsuar a2d76cac5a Fix Slack file upload (#135818)
* pgrade Slack integration to use AsyncWebClient and support files_upload_v2

- Replaced deprecated WebClient with AsyncWebClient throughout the integration.
- Removed the unsupported `run_async` parameter.
- Added a helper function to resolve channel names to channel IDs.
- Updated `_async_send_local_file_message` and `_async_send_remote_file_message` to handle Slack's new API requirements, including per-channel uploads.
- Updated dependency from slackclient==2.5.0 to slack-sdk>=3.0.0.
- Improved error handling and logging for channel resolution and file uploads.

* Fix test to use AsyncWebClient for Slack authentication flow

* Fix Slack authentication URL by removing the www subdomain

* Refactor Slack file upload functionality and add utility for file uploads
2025-01-19 21:09:04 +01:00

34 lines
1.1 KiB
Python

"""The slack integration."""
from __future__ import annotations
from slack_sdk.web.async_client import AsyncWebClient
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."""
def __init__(
self,
data: dict[str, AsyncWebClient],
description: EntityDescription,
entry: ConfigEntry,
) -> None:
"""Initialize a Slack entity."""
self._client: AsyncWebClient = 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=str(data[ATTR_URL]),
entry_type=DeviceEntryType.SERVICE,
identifiers={(DOMAIN, entry.entry_id)},
manufacturer=DEFAULT_NAME,
name=entry.title,
)