mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Remove deprecated max_health
, habits
and rewards
sensors from Habitica integration (#148377)
This commit is contained in:
parent
fc53ddb3b4
commit
e3cc4acdc6
@ -82,9 +82,6 @@
|
||||
"0": "mdi:skull-outline"
|
||||
}
|
||||
},
|
||||
"health_max": {
|
||||
"default": "mdi:heart"
|
||||
},
|
||||
"mana": {
|
||||
"default": "mdi:flask",
|
||||
"state": {
|
||||
@ -121,12 +118,6 @@
|
||||
"rogue": "mdi:ninja"
|
||||
}
|
||||
},
|
||||
"habits": {
|
||||
"default": "mdi:contrast-box"
|
||||
},
|
||||
"rewards": {
|
||||
"default": "mdi:treasure-chest"
|
||||
},
|
||||
"strength": {
|
||||
"default": "mdi:arm-flex-outline"
|
||||
},
|
||||
|
@ -2,43 +2,26 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable, Mapping
|
||||
from dataclasses import asdict, dataclass
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from enum import StrEnum
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from habiticalib import (
|
||||
ContentData,
|
||||
HabiticaClass,
|
||||
TaskData,
|
||||
TaskType,
|
||||
UserData,
|
||||
deserialize_task,
|
||||
ha,
|
||||
)
|
||||
from habiticalib import ContentData, HabiticaClass, TaskData, UserData, ha
|
||||
|
||||
from homeassistant.components.automation import automations_with_entity
|
||||
from homeassistant.components.script import scripts_with_entity
|
||||
from homeassistant.components.sensor import (
|
||||
DOMAIN as SENSOR_DOMAIN,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.issue_registry import (
|
||||
IssueSeverity,
|
||||
async_create_issue,
|
||||
async_delete_issue,
|
||||
)
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .const import ASSETS_URL, DOMAIN
|
||||
from .coordinator import HabiticaConfigEntry, HabiticaDataUpdateCoordinator
|
||||
from .const import ASSETS_URL
|
||||
from .coordinator import HabiticaConfigEntry
|
||||
from .entity import HabiticaBase
|
||||
from .util import (
|
||||
get_attribute_points,
|
||||
@ -84,7 +67,6 @@ class HabiticaSensorEntity(StrEnum):
|
||||
|
||||
DISPLAY_NAME = "display_name"
|
||||
HEALTH = "health"
|
||||
HEALTH_MAX = "health_max"
|
||||
MANA = "mana"
|
||||
MANA_MAX = "mana_max"
|
||||
EXPERIENCE = "experience"
|
||||
@ -136,12 +118,6 @@ SENSOR_DESCRIPTIONS: tuple[HabiticaSensorEntityDescription, ...] = (
|
||||
value_fn=lambda user, _: user.stats.hp,
|
||||
entity_picture=ha.HP,
|
||||
),
|
||||
HabiticaSensorEntityDescription(
|
||||
key=HabiticaSensorEntity.HEALTH_MAX,
|
||||
translation_key=HabiticaSensorEntity.HEALTH_MAX,
|
||||
entity_registry_enabled_default=False,
|
||||
value_fn=lambda user, _: 50,
|
||||
),
|
||||
HabiticaSensorEntityDescription(
|
||||
key=HabiticaSensorEntity.MANA,
|
||||
translation_key=HabiticaSensorEntity.MANA,
|
||||
@ -286,57 +262,6 @@ SENSOR_DESCRIPTIONS: tuple[HabiticaSensorEntityDescription, ...] = (
|
||||
)
|
||||
|
||||
|
||||
TASKS_MAP_ID = "id"
|
||||
TASKS_MAP = {
|
||||
"repeat": "repeat",
|
||||
"challenge": "challenge",
|
||||
"group": "group",
|
||||
"frequency": "frequency",
|
||||
"every_x": "everyX",
|
||||
"streak": "streak",
|
||||
"up": "up",
|
||||
"down": "down",
|
||||
"counter_up": "counterUp",
|
||||
"counter_down": "counterDown",
|
||||
"next_due": "nextDue",
|
||||
"yester_daily": "yesterDaily",
|
||||
"completed": "completed",
|
||||
"collapse_checklist": "collapseChecklist",
|
||||
"type": "Type",
|
||||
"notes": "notes",
|
||||
"tags": "tags",
|
||||
"value": "value",
|
||||
"priority": "priority",
|
||||
"start_date": "startDate",
|
||||
"days_of_month": "daysOfMonth",
|
||||
"weeks_of_month": "weeksOfMonth",
|
||||
"created_at": "createdAt",
|
||||
"text": "text",
|
||||
"is_due": "isDue",
|
||||
}
|
||||
|
||||
|
||||
TASK_SENSOR_DESCRIPTION: tuple[HabiticaTaskSensorEntityDescription, ...] = (
|
||||
HabiticaTaskSensorEntityDescription(
|
||||
key=HabiticaSensorEntity.HABITS,
|
||||
translation_key=HabiticaSensorEntity.HABITS,
|
||||
value_fn=lambda tasks: [r for r in tasks if r.Type is TaskType.HABIT],
|
||||
),
|
||||
HabiticaTaskSensorEntityDescription(
|
||||
key=HabiticaSensorEntity.REWARDS,
|
||||
translation_key=HabiticaSensorEntity.REWARDS,
|
||||
value_fn=lambda tasks: [r for r in tasks if r.Type is TaskType.REWARD],
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def entity_used_in(hass: HomeAssistant, entity_id: str) -> list[str]:
|
||||
"""Get list of related automations and scripts."""
|
||||
used_in = automations_with_entity(hass, entity_id)
|
||||
used_in += scripts_with_entity(hass, entity_id)
|
||||
return used_in
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: HabiticaConfigEntry,
|
||||
@ -345,59 +270,10 @@ async def async_setup_entry(
|
||||
"""Set up the habitica sensors."""
|
||||
|
||||
coordinator = config_entry.runtime_data
|
||||
ent_reg = er.async_get(hass)
|
||||
entities: list[SensorEntity] = []
|
||||
description: SensorEntityDescription
|
||||
|
||||
def add_deprecated_entity(
|
||||
description: SensorEntityDescription,
|
||||
entity_cls: Callable[
|
||||
[HabiticaDataUpdateCoordinator, SensorEntityDescription], SensorEntity
|
||||
],
|
||||
) -> None:
|
||||
"""Add deprecated entities."""
|
||||
if entity_id := ent_reg.async_get_entity_id(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
f"{config_entry.unique_id}_{description.key}",
|
||||
):
|
||||
entity_entry = ent_reg.async_get(entity_id)
|
||||
if entity_entry and entity_entry.disabled:
|
||||
ent_reg.async_remove(entity_id)
|
||||
async_delete_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
f"deprecated_entity_{description.key}",
|
||||
async_add_entities(
|
||||
HabiticaSensor(coordinator, description) for description in SENSOR_DESCRIPTIONS
|
||||
)
|
||||
elif entity_entry:
|
||||
entities.append(entity_cls(coordinator, description))
|
||||
if entity_used_in(hass, entity_id):
|
||||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
f"deprecated_entity_{description.key}",
|
||||
breaks_in_ha_version="2025.8.0",
|
||||
is_fixable=False,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_entity",
|
||||
translation_placeholders={
|
||||
"name": str(
|
||||
entity_entry.name or entity_entry.original_name
|
||||
),
|
||||
"entity": entity_id,
|
||||
},
|
||||
)
|
||||
|
||||
for description in SENSOR_DESCRIPTIONS:
|
||||
if description.key is HabiticaSensorEntity.HEALTH_MAX:
|
||||
add_deprecated_entity(description, HabiticaSensor)
|
||||
else:
|
||||
entities.append(HabiticaSensor(coordinator, description))
|
||||
|
||||
for description in TASK_SENSOR_DESCRIPTION:
|
||||
add_deprecated_entity(description, HabiticaTaskSensor)
|
||||
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
class HabiticaSensor(HabiticaBase, SensorEntity):
|
||||
@ -441,31 +317,3 @@ class HabiticaSensor(HabiticaBase, SensorEntity):
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
class HabiticaTaskSensor(HabiticaBase, SensorEntity):
|
||||
"""A Habitica task sensor."""
|
||||
|
||||
entity_description: HabiticaTaskSensorEntityDescription
|
||||
|
||||
@property
|
||||
def native_value(self) -> StateType:
|
||||
"""Return the state of the device."""
|
||||
|
||||
return len(self.entity_description.value_fn(self.coordinator.data.tasks))
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> Mapping[str, Any] | None:
|
||||
"""Return the state attributes of all user tasks."""
|
||||
attrs = {}
|
||||
|
||||
# Map tasks to TASKS_MAP
|
||||
for task_data in self.entity_description.value_fn(self.coordinator.data.tasks):
|
||||
received_task = deserialize_task(asdict(task_data))
|
||||
task_id = received_task[TASKS_MAP_ID]
|
||||
task = {}
|
||||
for map_key, map_value in TASKS_MAP.items():
|
||||
if value := received_task.get(map_value):
|
||||
task[map_key] = value
|
||||
attrs[str(task_id)] = task
|
||||
return attrs
|
||||
|
@ -4,7 +4,6 @@
|
||||
"dailies": "Dailies",
|
||||
"config_entry_name": "Select character",
|
||||
"task_name": "Task name",
|
||||
"unit_tasks": "tasks",
|
||||
"unit_health_points": "HP",
|
||||
"unit_mana_points": "MP",
|
||||
"unit_experience_points": "XP",
|
||||
@ -276,10 +275,6 @@
|
||||
"name": "Health",
|
||||
"unit_of_measurement": "[%key:component::habitica::common::unit_health_points%]"
|
||||
},
|
||||
"health_max": {
|
||||
"name": "Max. health",
|
||||
"unit_of_measurement": "[%key:component::habitica::common::unit_health_points%]"
|
||||
},
|
||||
"mana": {
|
||||
"name": "Mana",
|
||||
"unit_of_measurement": "[%key:component::habitica::common::unit_mana_points%]"
|
||||
@ -319,14 +314,6 @@
|
||||
"rogue": "Rogue"
|
||||
}
|
||||
},
|
||||
"habits": {
|
||||
"name": "Habits",
|
||||
"unit_of_measurement": "[%key:component::habitica::common::unit_tasks%]"
|
||||
},
|
||||
"rewards": {
|
||||
"name": "Rewards",
|
||||
"unit_of_measurement": "[%key:component::habitica::common::unit_tasks%]"
|
||||
},
|
||||
"strength": {
|
||||
"name": "Strength",
|
||||
"state_attributes": {
|
||||
|
@ -381,214 +381,6 @@
|
||||
'state': '137.625872146098',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.test_user_habits-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.test_user_habits',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Habits',
|
||||
'platform': 'habitica',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': 'test_user_habits',
|
||||
'supported_features': 0,
|
||||
'translation_key': <HabiticaSensorEntity.HABITS: 'habits'>,
|
||||
'unique_id': 'a380546a-94be-4b8e-8a0b-23e0d5c03303_habits',
|
||||
'unit_of_measurement': 'tasks',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.test_user_habits-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'1d147de6-5c02-4740-8e2f-71d3015a37f4': dict({
|
||||
'challenge': dict({
|
||||
'broken': None,
|
||||
'id': None,
|
||||
'shortName': None,
|
||||
'taskId': None,
|
||||
'winner': None,
|
||||
}),
|
||||
'created_at': '2024-07-07T17:51:53.266000+00:00',
|
||||
'frequency': 'daily',
|
||||
'group': dict({
|
||||
'assignedDate': None,
|
||||
'assignedUsers': list([
|
||||
]),
|
||||
'assignedUsersDetail': dict({
|
||||
}),
|
||||
'assigningUsername': None,
|
||||
'completedBy': dict({
|
||||
'date': None,
|
||||
'userId': None,
|
||||
}),
|
||||
'id': None,
|
||||
'managerNotes': None,
|
||||
'taskId': None,
|
||||
}),
|
||||
'priority': 1,
|
||||
'repeat': dict({
|
||||
'f': False,
|
||||
'm': True,
|
||||
's': False,
|
||||
'su': False,
|
||||
't': True,
|
||||
'th': False,
|
||||
'w': True,
|
||||
}),
|
||||
'text': 'Eine kurze Pause machen',
|
||||
'type': 'habit',
|
||||
'up': True,
|
||||
}),
|
||||
'bc1d1855-b2b8-4663-98ff-62e7b763dfc4': dict({
|
||||
'challenge': dict({
|
||||
'broken': None,
|
||||
'id': None,
|
||||
'shortName': None,
|
||||
'taskId': None,
|
||||
'winner': None,
|
||||
}),
|
||||
'created_at': '2024-07-07T17:51:53.265000+00:00',
|
||||
'down': True,
|
||||
'frequency': 'daily',
|
||||
'group': dict({
|
||||
'assignedDate': None,
|
||||
'assignedUsers': list([
|
||||
]),
|
||||
'assignedUsersDetail': dict({
|
||||
}),
|
||||
'assigningUsername': None,
|
||||
'completedBy': dict({
|
||||
'date': None,
|
||||
'userId': None,
|
||||
}),
|
||||
'id': None,
|
||||
'managerNotes': None,
|
||||
'taskId': None,
|
||||
}),
|
||||
'notes': 'Oder lösche es über die Bearbeitungs-Ansicht',
|
||||
'priority': 1,
|
||||
'repeat': dict({
|
||||
'f': False,
|
||||
'm': True,
|
||||
's': False,
|
||||
'su': False,
|
||||
't': True,
|
||||
'th': False,
|
||||
'w': True,
|
||||
}),
|
||||
'text': 'Klicke hier um dies als schlechte Gewohnheit zu markieren, die Du gerne loswerden möchtest',
|
||||
'type': 'habit',
|
||||
}),
|
||||
'e97659e0-2c42-4599-a7bb-00282adc410d': dict({
|
||||
'challenge': dict({
|
||||
'broken': None,
|
||||
'id': None,
|
||||
'shortName': None,
|
||||
'taskId': None,
|
||||
'winner': None,
|
||||
}),
|
||||
'created_at': '2024-07-07T17:51:53.264000+00:00',
|
||||
'frequency': 'daily',
|
||||
'group': dict({
|
||||
'assignedDate': None,
|
||||
'assignedUsers': list([
|
||||
]),
|
||||
'assignedUsersDetail': dict({
|
||||
}),
|
||||
'assigningUsername': None,
|
||||
'completedBy': dict({
|
||||
'date': None,
|
||||
'userId': None,
|
||||
}),
|
||||
'id': None,
|
||||
'managerNotes': None,
|
||||
'taskId': None,
|
||||
}),
|
||||
'notes': 'Eine Gewohnheit, eine Tagesaufgabe oder ein To-Do',
|
||||
'priority': 1,
|
||||
'repeat': dict({
|
||||
'f': False,
|
||||
'm': True,
|
||||
's': False,
|
||||
'su': False,
|
||||
't': True,
|
||||
'th': False,
|
||||
'w': True,
|
||||
}),
|
||||
'text': 'Füge eine Aufgabe zu Habitica hinzu',
|
||||
'type': 'habit',
|
||||
'up': True,
|
||||
}),
|
||||
'f21fa608-cfc6-4413-9fc7-0eb1b48ca43a': dict({
|
||||
'challenge': dict({
|
||||
'broken': None,
|
||||
'id': None,
|
||||
'shortName': None,
|
||||
'taskId': None,
|
||||
'winner': None,
|
||||
}),
|
||||
'created_at': '2024-07-07T17:51:53.268000+00:00',
|
||||
'down': True,
|
||||
'frequency': 'daily',
|
||||
'group': dict({
|
||||
'assignedDate': None,
|
||||
'assignedUsers': list([
|
||||
]),
|
||||
'assignedUsersDetail': dict({
|
||||
}),
|
||||
'assigningUsername': None,
|
||||
'completedBy': dict({
|
||||
'date': None,
|
||||
'userId': None,
|
||||
}),
|
||||
'id': None,
|
||||
'managerNotes': None,
|
||||
'taskId': None,
|
||||
}),
|
||||
'priority': 1,
|
||||
'repeat': dict({
|
||||
'f': False,
|
||||
'm': True,
|
||||
's': False,
|
||||
'su': False,
|
||||
't': True,
|
||||
'th': False,
|
||||
'w': True,
|
||||
}),
|
||||
'text': 'Gesundes Essen/Junkfood',
|
||||
'type': 'habit',
|
||||
'up': True,
|
||||
}),
|
||||
'friendly_name': 'test-user Habits',
|
||||
'unit_of_measurement': 'tasks',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.test_user_habits',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '4',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.test_user_hatching_potions-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
@ -853,55 +645,6 @@
|
||||
'state': '50.9',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.test_user_max_health-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.test_user_max_health',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Max. health',
|
||||
'platform': 'habitica',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': 'test_user_max_health',
|
||||
'supported_features': 0,
|
||||
'translation_key': <HabiticaSensorEntity.HEALTH_MAX: 'health_max'>,
|
||||
'unique_id': 'a380546a-94be-4b8e-8a0b-23e0d5c03303_health_max',
|
||||
'unit_of_measurement': 'HP',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.test_user_max_health-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'test-user Max. health',
|
||||
'unit_of_measurement': 'HP',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.test_user_max_health',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '50',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.test_user_max_mana-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
@ -1321,98 +1064,6 @@
|
||||
'state': '2',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.test_user_rewards-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.test_user_rewards',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Rewards',
|
||||
'platform': 'habitica',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': 'test_user_rewards',
|
||||
'supported_features': 0,
|
||||
'translation_key': <HabiticaSensorEntity.REWARDS: 'rewards'>,
|
||||
'unique_id': 'a380546a-94be-4b8e-8a0b-23e0d5c03303_rewards',
|
||||
'unit_of_measurement': 'tasks',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.test_user_rewards-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'5e2ea1df-f6e6-4ba3-bccb-97c5ec63e99b': dict({
|
||||
'challenge': dict({
|
||||
'broken': None,
|
||||
'id': None,
|
||||
'shortName': None,
|
||||
'taskId': None,
|
||||
'winner': None,
|
||||
}),
|
||||
'created_at': '2024-07-07T17:51:53.266000+00:00',
|
||||
'group': dict({
|
||||
'assignedDate': None,
|
||||
'assignedUsers': list([
|
||||
]),
|
||||
'assignedUsersDetail': dict({
|
||||
}),
|
||||
'assigningUsername': None,
|
||||
'completedBy': dict({
|
||||
'date': None,
|
||||
'userId': None,
|
||||
}),
|
||||
'id': None,
|
||||
'managerNotes': None,
|
||||
'taskId': None,
|
||||
}),
|
||||
'notes': 'Schaue fern, spiele ein Spiel, gönne Dir einen Leckerbissen, es liegt ganz bei Dir!',
|
||||
'priority': 1,
|
||||
'repeat': dict({
|
||||
'f': False,
|
||||
'm': True,
|
||||
's': False,
|
||||
'su': False,
|
||||
't': True,
|
||||
'th': False,
|
||||
'w': True,
|
||||
}),
|
||||
'tags': list([
|
||||
'3450351f-1323-4c7e-9fd2-0cdff25b3ce0',
|
||||
'b2780f82-b3b5-49a3-a677-48f2c8c7e3bb',
|
||||
]),
|
||||
'text': 'Belohne Dich selbst',
|
||||
'type': 'reward',
|
||||
'value': 10.0,
|
||||
}),
|
||||
'friendly_name': 'test-user Rewards',
|
||||
'unit_of_measurement': 'tasks',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.test_user_rewards',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '1',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.test_user_saddles-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
|
@ -6,13 +6,10 @@ from unittest.mock import patch
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.habitica.const import DOMAIN
|
||||
from homeassistant.components.habitica.sensor import HabiticaSensorEntity
|
||||
from homeassistant.components.sensor.const import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er, issue_registry as ir
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
@ -36,19 +33,6 @@ async def test_sensors(
|
||||
) -> None:
|
||||
"""Test setup of the Habitica sensor platform."""
|
||||
|
||||
for entity in (
|
||||
("test_user_habits", "habits"),
|
||||
("test_user_rewards", "rewards"),
|
||||
("test_user_max_health", "health_max"),
|
||||
):
|
||||
entity_registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
f"a380546a-94be-4b8e-8a0b-23e0d5c03303_{entity[1]}",
|
||||
suggested_object_id=entity[0],
|
||||
disabled_by=None,
|
||||
)
|
||||
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
@ -56,96 +40,3 @@ async def test_sensors(
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("entity_id", "key"),
|
||||
[
|
||||
("test_user_habits", HabiticaSensorEntity.HABITS),
|
||||
("test_user_rewards", HabiticaSensorEntity.REWARDS),
|
||||
("test_user_max_health", HabiticaSensorEntity.HEALTH_MAX),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("habitica", "entity_registry_enabled_by_default")
|
||||
async def test_sensor_deprecation_issue(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
entity_id: str,
|
||||
key: HabiticaSensorEntity,
|
||||
) -> None:
|
||||
"""Test sensor deprecation issue."""
|
||||
entity_registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
f"a380546a-94be-4b8e-8a0b-23e0d5c03303_{key}",
|
||||
suggested_object_id=entity_id,
|
||||
disabled_by=None,
|
||||
)
|
||||
|
||||
assert entity_registry is not None
|
||||
with patch(
|
||||
"homeassistant.components.habitica.sensor.entity_used_in", return_value=True
|
||||
):
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
assert entity_registry.async_get(f"sensor.{entity_id}") is not None
|
||||
assert issue_registry.async_get_issue(
|
||||
domain=DOMAIN,
|
||||
issue_id=f"deprecated_entity_{key}",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("entity_id", "key"),
|
||||
[
|
||||
("test_user_habits", HabiticaSensorEntity.HABITS),
|
||||
("test_user_rewards", HabiticaSensorEntity.REWARDS),
|
||||
("test_user_max_health", HabiticaSensorEntity.HEALTH_MAX),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("habitica", "entity_registry_enabled_by_default")
|
||||
async def test_sensor_deprecation_delete_disabled(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
entity_id: str,
|
||||
key: HabiticaSensorEntity,
|
||||
) -> None:
|
||||
"""Test sensor deletion ."""
|
||||
|
||||
entity_registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
f"a380546a-94be-4b8e-8a0b-23e0d5c03303_{key}",
|
||||
suggested_object_id=entity_id,
|
||||
disabled_by=er.RegistryEntryDisabler.USER,
|
||||
)
|
||||
|
||||
assert entity_registry is not None
|
||||
with patch(
|
||||
"homeassistant.components.habitica.sensor.entity_used_in", return_value=True
|
||||
):
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
assert (
|
||||
issue_registry.async_get_issue(
|
||||
domain=DOMAIN,
|
||||
issue_id=f"deprecated_entity_{key}",
|
||||
)
|
||||
is None
|
||||
)
|
||||
|
||||
assert entity_registry.async_get(f"sensor.{entity_id}") is None
|
||||
|
Loading…
x
Reference in New Issue
Block a user