Skip to content

Commit

Permalink
Simplify adding of entities in platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
elmurato committed Sep 9, 2023
1 parent 4ac3826 commit 7fe245c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
27 changes: 15 additions & 12 deletions homeassistant/components/minecraft_server/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ class MinecraftServerBinarySensorEntityDescription(BinarySensorEntityDescription
"""Class describing Minecraft Server binary sensor entities."""


STATUS_BINARY_SENSOR_DESCRIPTION = MinecraftServerBinarySensorEntityDescription(
key=KEY_STATUS,
translation_key=KEY_STATUS,
device_class=BinarySensorDeviceClass.CONNECTIVITY,
icon=ICON_STATUS,
)
BINARY_SENSOR_DESCRIPTIONS = [
MinecraftServerBinarySensorEntityDescription(
key=KEY_STATUS,
translation_key=KEY_STATUS,
device_class=BinarySensorDeviceClass.CONNECTIVITY,
icon=ICON_STATUS,
),
]


async def async_setup_entry(
Expand All @@ -36,13 +38,14 @@ async def async_setup_entry(
"""Set up the Minecraft Server binary sensor platform."""
server = hass.data[DOMAIN][config_entry.entry_id]

# Create entities list.
entities = [
MinecraftServerBinarySensorEntity(server, STATUS_BINARY_SENSOR_DESCRIPTION)
]

# Add binary sensor entities.
async_add_entities(entities, True)
async_add_entities(
[
MinecraftServerBinarySensorEntity(server=server, description=description)
for description in BINARY_SENSOR_DESCRIPTIONS
],
True,
)


class MinecraftServerBinarySensorEntity(MinecraftServerEntity, BinarySensorEntity):
Expand Down
16 changes: 7 additions & 9 deletions homeassistant/components/minecraft_server/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,14 @@ async def async_setup_entry(
"""Set up the Minecraft Server sensor platform."""
server = hass.data[DOMAIN][config_entry.entry_id]

# Create entities list.
entities = []

for description in SENSOR_DESCRIPTIONS:
entities.append(
MinecraftServerSensorEntity(server=server, description=description)
)

# Add sensor entities.
async_add_entities(entities, True)
async_add_entities(
[
MinecraftServerSensorEntity(server=server, description=description)
for description in SENSOR_DESCRIPTIONS
],
True,
)


class MinecraftServerSensorEntity(MinecraftServerEntity, SensorEntity):
Expand Down

0 comments on commit 7fe245c

Please sign in to comment.