EntityDescription doesn't need to be generic for NextDNS binary sensor and switch platforms (#116697)

pull/116699/head
Maciej Bieniek 2024-05-03 13:56:38 +02:00 committed by GitHub
parent cb26e3c633
commit 3c3a948c33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 82 additions and 87 deletions

View File

@ -4,7 +4,6 @@ from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from typing import Generic
from nextdns import ConnectionStatus
@ -19,29 +18,27 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import NextDnsConfigEntry
from .coordinator import CoordinatorDataT, NextDnsUpdateCoordinator
from .coordinator import NextDnsUpdateCoordinator
PARALLEL_UPDATES = 1
@dataclass(frozen=True, kw_only=True)
class NextDnsBinarySensorEntityDescription(
BinarySensorEntityDescription, Generic[CoordinatorDataT]
):
class NextDnsBinarySensorEntityDescription(BinarySensorEntityDescription):
"""NextDNS binary sensor entity description."""
state: Callable[[CoordinatorDataT, str], bool]
state: Callable[[ConnectionStatus, str], bool]
SENSORS = (
NextDnsBinarySensorEntityDescription[ConnectionStatus](
NextDnsBinarySensorEntityDescription(
key="this_device_nextdns_connection_status",
entity_category=EntityCategory.DIAGNOSTIC,
translation_key="device_connection_status",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
state=lambda data, _: data.connected,
),
NextDnsBinarySensorEntityDescription[ConnectionStatus](
NextDnsBinarySensorEntityDescription(
key="this_device_profile_connection_status",
entity_category=EntityCategory.DIAGNOSTIC,
translation_key="device_profile_connection_status",

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from typing import Any, Generic
from typing import Any
from aiohttp import ClientError
from aiohttp.client_exceptions import ClientConnectorError
@ -18,503 +18,501 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import NextDnsConfigEntry
from .coordinator import CoordinatorDataT, NextDnsUpdateCoordinator
from .coordinator import NextDnsUpdateCoordinator
PARALLEL_UPDATES = 1
@dataclass(frozen=True, kw_only=True)
class NextDnsSwitchEntityDescription(
SwitchEntityDescription, Generic[CoordinatorDataT]
):
class NextDnsSwitchEntityDescription(SwitchEntityDescription):
"""NextDNS switch entity description."""
state: Callable[[CoordinatorDataT], bool]
state: Callable[[Settings], bool]
SWITCHES = (
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_page",
translation_key="block_page",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.block_page,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="cache_boost",
translation_key="cache_boost",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.cache_boost,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="cname_flattening",
translation_key="cname_flattening",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.cname_flattening,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="anonymized_ecs",
translation_key="anonymized_ecs",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.anonymized_ecs,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="logs",
translation_key="logs",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.logs,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="web3",
translation_key="web3",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.web3,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="allow_affiliate",
translation_key="allow_affiliate",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.allow_affiliate,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_disguised_trackers",
translation_key="block_disguised_trackers",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.block_disguised_trackers,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="ai_threat_detection",
translation_key="ai_threat_detection",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.ai_threat_detection,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_csam",
translation_key="block_csam",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.block_csam,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_ddns",
translation_key="block_ddns",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.block_ddns,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_nrd",
translation_key="block_nrd",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.block_nrd,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_parked_domains",
translation_key="block_parked_domains",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.block_parked_domains,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="cryptojacking_protection",
translation_key="cryptojacking_protection",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.cryptojacking_protection,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="dga_protection",
translation_key="dga_protection",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.dga_protection,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="dns_rebinding_protection",
translation_key="dns_rebinding_protection",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.dns_rebinding_protection,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="google_safe_browsing",
translation_key="google_safe_browsing",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.google_safe_browsing,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="idn_homograph_attacks_protection",
translation_key="idn_homograph_attacks_protection",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.idn_homograph_attacks_protection,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="threat_intelligence_feeds",
translation_key="threat_intelligence_feeds",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.threat_intelligence_feeds,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="typosquatting_protection",
translation_key="typosquatting_protection",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.typosquatting_protection,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_bypass_methods",
translation_key="block_bypass_methods",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.block_bypass_methods,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="safesearch",
translation_key="safesearch",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.safesearch,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="youtube_restricted_mode",
translation_key="youtube_restricted_mode",
entity_category=EntityCategory.CONFIG,
state=lambda data: data.youtube_restricted_mode,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_9gag",
translation_key="block_9gag",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_9gag,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_amazon",
translation_key="block_amazon",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_amazon,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_bereal",
translation_key="block_bereal",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_bereal,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_blizzard",
translation_key="block_blizzard",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_blizzard,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_chatgpt",
translation_key="block_chatgpt",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_chatgpt,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_dailymotion",
translation_key="block_dailymotion",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_dailymotion,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_discord",
translation_key="block_discord",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_discord,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_disneyplus",
translation_key="block_disneyplus",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_disneyplus,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_ebay",
translation_key="block_ebay",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_ebay,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_facebook",
translation_key="block_facebook",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_facebook,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_fortnite",
translation_key="block_fortnite",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_fortnite,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_google_chat",
translation_key="block_google_chat",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_google_chat,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_hbomax",
translation_key="block_hbomax",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_hbomax,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_hulu",
name="Block Hulu",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_hulu,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_imgur",
translation_key="block_imgur",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_imgur,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_instagram",
translation_key="block_instagram",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_instagram,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_leagueoflegends",
translation_key="block_leagueoflegends",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_leagueoflegends,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_mastodon",
translation_key="block_mastodon",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_mastodon,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_messenger",
translation_key="block_messenger",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_messenger,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_minecraft",
translation_key="block_minecraft",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_minecraft,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_netflix",
translation_key="block_netflix",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_netflix,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_pinterest",
translation_key="block_pinterest",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_pinterest,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_playstation_network",
translation_key="block_playstation_network",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_playstation_network,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_primevideo",
translation_key="block_primevideo",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_primevideo,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_reddit",
translation_key="block_reddit",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_reddit,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_roblox",
translation_key="block_roblox",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_roblox,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_signal",
translation_key="block_signal",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_signal,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_skype",
translation_key="block_skype",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_skype,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_snapchat",
translation_key="block_snapchat",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_snapchat,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_spotify",
translation_key="block_spotify",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_spotify,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_steam",
translation_key="block_steam",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_steam,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_telegram",
translation_key="block_telegram",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_telegram,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_tiktok",
translation_key="block_tiktok",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_tiktok,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_tinder",
translation_key="block_tinder",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_tinder,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_tumblr",
translation_key="block_tumblr",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_tumblr,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_twitch",
translation_key="block_twitch",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_twitch,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_twitter",
translation_key="block_twitter",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_twitter,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_vimeo",
translation_key="block_vimeo",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_vimeo,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_vk",
translation_key="block_vk",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_vk,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_whatsapp",
translation_key="block_whatsapp",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_whatsapp,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_xboxlive",
translation_key="block_xboxlive",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_xboxlive,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_youtube",
translation_key="block_youtube",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_youtube,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_zoom",
translation_key="block_zoom",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_zoom,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_dating",
translation_key="block_dating",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_dating,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_gambling",
translation_key="block_gambling",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_gambling,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_online_gaming",
translation_key="block_online_gaming",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_online_gaming,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_piracy",
translation_key="block_piracy",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_piracy,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_porn",
translation_key="block_porn",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_porn,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_social_networks",
translation_key="block_social_networks",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
state=lambda data: data.block_social_networks,
),
NextDnsSwitchEntityDescription[Settings](
NextDnsSwitchEntityDescription(
key="block_video_streaming",
translation_key="block_video_streaming",
entity_category=EntityCategory.CONFIG,