Skip to content

Commit

Permalink
Set category and enabled by default of Minecraft Server sensors (home…
Browse files Browse the repository at this point in the history
…-assistant#101943)

* Use set instead of list for supported server types in sensor platform

* Set sensor categories and enabled by default

* Set edition and version as diagnostic sensors
  • Loading branch information
elmurato authored Oct 13, 2023
1 parent ce77566 commit a302f1a
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions homeassistant/components/minecraft_server/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_TYPE, UnitOfTime
from homeassistant.const import CONF_TYPE, EntityCategory, UnitOfTime
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
Expand Down Expand Up @@ -47,7 +47,7 @@ class MinecraftServerEntityDescriptionMixin:

value_fn: Callable[[MinecraftServerData], StateType]
attributes_fn: Callable[[MinecraftServerData], MutableMapping[str, Any]] | None
supported_server_types: list[MinecraftServerType]
supported_server_types: set[MinecraftServerType]


@dataclass
Expand Down Expand Up @@ -77,21 +77,24 @@ def get_extra_state_attributes_players_list(
icon=ICON_VERSION,
value_fn=lambda data: data.version,
attributes_fn=None,
supported_server_types=[
supported_server_types={
MinecraftServerType.JAVA_EDITION,
MinecraftServerType.BEDROCK_EDITION,
],
},
entity_category=EntityCategory.DIAGNOSTIC,
),
MinecraftServerSensorEntityDescription(
key=KEY_PROTOCOL_VERSION,
translation_key=KEY_PROTOCOL_VERSION,
icon=ICON_PROTOCOL_VERSION,
value_fn=lambda data: data.protocol_version,
attributes_fn=None,
supported_server_types=[
supported_server_types={
MinecraftServerType.JAVA_EDITION,
MinecraftServerType.BEDROCK_EDITION,
],
},
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
MinecraftServerSensorEntityDescription(
key=KEY_PLAYERS_MAX,
Expand All @@ -100,10 +103,11 @@ def get_extra_state_attributes_players_list(
icon=ICON_PLAYERS_MAX,
value_fn=lambda data: data.players_max,
attributes_fn=None,
supported_server_types=[
supported_server_types={
MinecraftServerType.JAVA_EDITION,
MinecraftServerType.BEDROCK_EDITION,
],
},
entity_registry_enabled_default=False,
),
MinecraftServerSensorEntityDescription(
key=KEY_LATENCY,
Expand All @@ -113,21 +117,22 @@ def get_extra_state_attributes_players_list(
icon=ICON_LATENCY,
value_fn=lambda data: data.latency,
attributes_fn=None,
supported_server_types=[
supported_server_types={
MinecraftServerType.JAVA_EDITION,
MinecraftServerType.BEDROCK_EDITION,
],
},
entity_category=EntityCategory.DIAGNOSTIC,
),
MinecraftServerSensorEntityDescription(
key=KEY_MOTD,
translation_key=KEY_MOTD,
icon=ICON_MOTD,
value_fn=lambda data: data.motd,
attributes_fn=None,
supported_server_types=[
supported_server_types={
MinecraftServerType.JAVA_EDITION,
MinecraftServerType.BEDROCK_EDITION,
],
},
),
MinecraftServerSensorEntityDescription(
key=KEY_PLAYERS_ONLINE,
Expand All @@ -136,40 +141,42 @@ def get_extra_state_attributes_players_list(
icon=ICON_PLAYERS_ONLINE,
value_fn=lambda data: data.players_online,
attributes_fn=get_extra_state_attributes_players_list,
supported_server_types=[
supported_server_types={
MinecraftServerType.JAVA_EDITION,
MinecraftServerType.BEDROCK_EDITION,
],
},
),
MinecraftServerSensorEntityDescription(
key=KEY_EDITION,
translation_key=KEY_EDITION,
icon=ICON_EDITION,
value_fn=lambda data: data.edition,
attributes_fn=None,
supported_server_types=[
supported_server_types={
MinecraftServerType.BEDROCK_EDITION,
],
},
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
MinecraftServerSensorEntityDescription(
key=KEY_GAME_MODE,
translation_key=KEY_GAME_MODE,
icon=ICON_GAME_MODE,
value_fn=lambda data: data.game_mode,
attributes_fn=None,
supported_server_types=[
supported_server_types={
MinecraftServerType.BEDROCK_EDITION,
],
},
),
MinecraftServerSensorEntityDescription(
key=KEY_MAP_NAME,
translation_key=KEY_MAP_NAME,
icon=ICON_MAP_NAME,
value_fn=lambda data: data.map_name,
attributes_fn=None,
supported_server_types=[
supported_server_types={
MinecraftServerType.BEDROCK_EDITION,
],
},
),
]

Expand Down

0 comments on commit a302f1a

Please sign in to comment.