Remove deprecated sensors in Habitica integration (#134320)

* Remove deprecated sensors

* remove todos/dailies also from enum
This commit is contained in:
Manu 2025-01-03 14:48:26 +01:00 committed by GitHub
parent 336af8b551
commit 9320ccfa4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 4 additions and 579 deletions

View File

@ -121,12 +121,6 @@
"rogue": "mdi:ninja"
}
},
"todos": {
"default": "mdi:checkbox-outline"
},
"dailys": {
"default": "mdi:calendar-month"
},
"habits": {
"default": "mdi:contrast-box"
},

View File

@ -6,7 +6,7 @@ from collections.abc import Callable, Mapping
from dataclasses import asdict, dataclass
from enum import StrEnum
import logging
from typing import TYPE_CHECKING, Any
from typing import Any
from habiticalib import (
ContentData,
@ -18,25 +18,18 @@ from habiticalib import (
)
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 AddEntitiesCallback
from homeassistant.helpers.issue_registry import (
IssueSeverity,
async_create_issue,
async_delete_issue,
)
from homeassistant.helpers.typing import StateType
from .const import ASSETS_URL, DOMAIN
from .const import ASSETS_URL
from .entity import HabiticaBase
from .types import HabiticaConfigEntry
from .util import entity_used_in, get_attribute_points, get_attributes_total
from .util import get_attribute_points, get_attributes_total
_LOGGER = logging.getLogger(__name__)
@ -73,8 +66,6 @@ class HabiticaSensorEntity(StrEnum):
GOLD = "gold"
CLASS = "class"
HABITS = "habits"
DAILIES = "dailys"
TODOS = "todos"
REWARDS = "rewards"
GEMS = "gems"
TRINKETS = "trinkets"
@ -227,22 +218,6 @@ TASK_SENSOR_DESCRIPTION: tuple[HabiticaTaskSensorEntityDescription, ...] = (
translation_key=HabiticaSensorEntity.HABITS,
value_fn=lambda tasks: [r for r in tasks if r.Type is TaskType.HABIT],
),
HabiticaTaskSensorEntityDescription(
key=HabiticaSensorEntity.DAILIES,
translation_key=HabiticaSensorEntity.DAILIES,
value_fn=lambda tasks: [r for r in tasks if r.Type is TaskType.DAILY],
entity_registry_enabled_default=False,
),
HabiticaTaskSensorEntityDescription(
key=HabiticaSensorEntity.TODOS,
translation_key=HabiticaSensorEntity.TODOS,
value_fn=(
lambda tasks: [
r for r in tasks if r.Type is TaskType.TODO and not r.completed
]
),
entity_registry_enabled_default=False,
),
HabiticaTaskSensorEntityDescription(
key=HabiticaSensorEntity.REWARDS,
translation_key=HabiticaSensorEntity.REWARDS,
@ -324,37 +299,3 @@ class HabiticaTaskSensor(HabiticaBase, SensorEntity):
task[map_key] = value
attrs[str(task_id)] = task
return attrs
async def async_added_to_hass(self) -> None:
"""Raise issue when entity is registered and was not disabled."""
if TYPE_CHECKING:
assert self.unique_id
if entity_id := er.async_get(self.hass).async_get_entity_id(
SENSOR_DOMAIN, DOMAIN, self.unique_id
):
if (
self.enabled
and self.entity_description.key
in (HabiticaSensorEntity.TODOS, HabiticaSensorEntity.DAILIES)
and entity_used_in(self.hass, entity_id)
):
async_create_issue(
self.hass,
DOMAIN,
f"deprecated_task_entity_{self.entity_description.key}",
breaks_in_ha_version="2025.2.0",
is_fixable=False,
severity=IssueSeverity.WARNING,
translation_key="deprecated_task_entity",
translation_placeholders={
"task_name": str(self.name),
"entity": entity_id,
},
)
else:
async_delete_issue(
self.hass,
DOMAIN,
f"deprecated_task_entity_{self.entity_description.key}",
)
await super().async_added_to_hass()

View File

@ -218,14 +218,6 @@
"rogue": "Rogue"
}
},
"todos": {
"name": "[%key:component::habitica::common::todos%]",
"unit_of_measurement": "[%key:component::habitica::common::unit_tasks%]"
},
"dailys": {
"name": "[%key:component::habitica::common::dailies%]",
"unit_of_measurement": "[%key:component::habitica::common::unit_tasks%]"
},
"habits": {
"name": "Habits",
"unit_of_measurement": "[%key:component::habitica::common::unit_tasks%]"
@ -404,10 +396,6 @@
}
},
"issues": {
"deprecated_task_entity": {
"title": "The Habitica {task_name} sensor is deprecated",
"description": "The Habitica entity `{entity}` is deprecated and will be removed in a future release.\nPlease update your automations and scripts to replace the sensor entity with the newly added todo entity.\nWhen you are done migrating you can disable `{entity}`."
},
"deprecated_api_call": {
"title": "The Habitica action habitica.api_call is deprecated",
"description": "The Habitica action `habitica.api_call` is deprecated and will be removed in Home Assistant 2025.5.0.\n\nPlease update your automations and scripts to use other Habitica actions and entities."

View File

@ -114,268 +114,6 @@
'state': '102',
})
# ---
# name: test_sensors[sensor.test_user_dailies-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.test_user_dailies',
'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': 'Dailies',
'platform': 'habitica',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': <HabiticaSensorEntity.DAILIES: 'dailys'>,
'unique_id': 'a380546a-94be-4b8e-8a0b-23e0d5c03303_dailys',
'unit_of_measurement': 'tasks',
})
# ---
# name: test_sensors[sensor.test_user_dailies-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'2c6d136c-a1c3-4bef-b7c4-fa980784b1e1': dict({
'challenge': dict({
'broken': None,
'id': None,
'shortName': None,
'taskId': None,
'winner': None,
}),
'created_at': '2024-09-22T11:44:43.774000+00:00',
'every_x': 1,
'frequency': 'weekly',
'group': dict({
'assignedDate': None,
'assignedUsers': list([
]),
'assignedUsersDetail': dict({
}),
'assigningUsername': None,
'completedBy': dict({
'date': None,
'userId': None,
}),
'id': None,
'managerNotes': None,
'taskId': None,
}),
'is_due': True,
'next_due': list([
'2024-09-24T22:00:00+00:00',
'2024-09-27T22:00:00+00:00',
'2024-09-28T22:00:00+00:00',
'2024-10-01T22:00:00+00:00',
'2024-10-04T22:00:00+00:00',
'2024-10-08T22:00:00+00:00',
]),
'notes': 'Ein einstündiges Workout im Fitnessstudio absolvieren.',
'priority': 2,
'repeat': dict({
'f': False,
'm': False,
's': True,
'su': True,
't': False,
'th': False,
'w': True,
}),
'start_date': '2024-09-21T22:00:00+00:00',
'tags': list([
'6aa65cbb-dc08-4fdd-9a66-7dedb7ba4cab',
]),
'text': 'Fitnessstudio besuchen',
'type': 'daily',
'yester_daily': True,
}),
'564b9ac9-c53d-4638-9e7f-1cd96fe19baa': dict({
'challenge': dict({
'broken': None,
'id': None,
'shortName': None,
'taskId': None,
'winner': None,
}),
'completed': True,
'created_at': '2024-07-07T17:51:53.268000+00:00',
'every_x': 1,
'frequency': 'weekly',
'group': dict({
'assignedDate': None,
'assignedUsers': list([
]),
'assignedUsersDetail': dict({
}),
'assigningUsername': None,
'completedBy': dict({
'date': None,
'userId': None,
}),
'id': None,
'managerNotes': None,
'taskId': None,
}),
'is_due': True,
'next_due': list([
'2024-09-23T00:00:00+02:00',
'2024-09-24T00:00:00+02:00',
'2024-09-25T00:00:00+02:00',
'2024-09-26T00:00:00+02:00',
'2024-09-27T00:00:00+02:00',
'2024-09-28T00:00:00+02:00',
]),
'notes': 'Klicke um Änderungen zu machen!',
'priority': 1,
'repeat': dict({
'f': True,
'm': True,
's': True,
'su': True,
't': True,
'th': True,
'w': True,
}),
'start_date': '2024-07-06T22:00:00+00:00',
'streak': 1,
'text': 'Zahnseide benutzen',
'type': 'daily',
'value': -2.9663035443712333,
'yester_daily': True,
}),
'6e53f1f5-a315-4edd-984d-8d762e4a08ef': dict({
'challenge': dict({
'broken': None,
'id': None,
'shortName': None,
'taskId': None,
'winner': None,
}),
'created_at': '2024-10-10T15:57:14.304000+00:00',
'every_x': 1,
'frequency': 'monthly',
'group': dict({
'assignedDate': None,
'assignedUsers': list([
]),
'assignedUsersDetail': dict({
}),
'assigningUsername': None,
'completedBy': dict({
'date': None,
'userId': None,
}),
'id': None,
'managerNotes': None,
'taskId': None,
}),
'next_due': list([
'2024-12-14T23:00:00+00:00',
'2025-01-18T23:00:00+00:00',
'2025-02-15T23:00:00+00:00',
'2025-03-15T23:00:00+00:00',
'2025-04-19T23:00:00+00:00',
'2025-05-17T23:00:00+00:00',
]),
'notes': 'Klicke um den Namen Deines aktuellen Projekts anzugeben & setze einen Terminplan!',
'priority': 1,
'repeat': dict({
'f': False,
'm': False,
's': False,
'su': True,
't': False,
'th': False,
'w': False,
}),
'start_date': '2024-09-20T23:00:00+00:00',
'streak': 1,
'text': 'Arbeite an einem kreativen Projekt',
'type': 'daily',
'value': -0.9215181434950852,
'weeks_of_month': list([
3,
]),
'yester_daily': True,
}),
'f2c85972-1a19-4426-bc6d-ce3337b9d99f': dict({
'challenge': dict({
'broken': None,
'id': None,
'shortName': None,
'taskId': None,
'winner': None,
}),
'created_at': '2024-07-07T17:51:53.266000+00:00',
'every_x': 1,
'frequency': 'weekly',
'group': dict({
'assignedDate': None,
'assignedUsers': list([
]),
'assignedUsersDetail': dict({
}),
'assigningUsername': None,
'completedBy': dict({
'date': None,
'userId': None,
}),
'id': None,
'managerNotes': None,
'taskId': None,
}),
'is_due': True,
'next_due': list([
'2024-09-22T22:00:00+00:00',
'2024-09-23T22:00:00+00:00',
'2024-09-24T22:00:00+00:00',
'2024-09-25T22:00:00+00:00',
'2024-09-26T22:00:00+00:00',
'2024-09-27T22:00:00+00:00',
]),
'notes': 'Klicke um Deinen Terminplan festzulegen!',
'priority': 1,
'repeat': dict({
'f': True,
'm': True,
's': True,
'su': True,
't': True,
'th': True,
'w': True,
}),
'start_date': '2024-07-06T22:00:00+00:00',
'text': '5 Minuten ruhig durchatmen',
'type': 'daily',
'value': -1.919611992979862,
'yester_daily': True,
}),
'friendly_name': 'test-user Dailies',
'unit_of_measurement': 'tasks',
}),
'context': <ANY>,
'entity_id': 'sensor.test_user_dailies',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '4',
})
# ---
# name: test_sensors[sensor.test_user_display_name-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
@ -1365,209 +1103,3 @@
'state': '104',
})
# ---
# name: test_sensors[sensor.test_user_to_do_s-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.test_user_to_do_s',
'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': "To-Do's",
'platform': 'habitica',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': <HabiticaSensorEntity.TODOS: 'todos'>,
'unique_id': 'a380546a-94be-4b8e-8a0b-23e0d5c03303_todos',
'unit_of_measurement': 'tasks',
})
# ---
# name: test_sensors[sensor.test_user_to_do_s-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'1aa3137e-ef72-4d1f-91ee-41933602f438': dict({
'challenge': dict({
'broken': None,
'id': None,
'shortName': None,
'taskId': None,
'winner': None,
}),
'created_at': '2024-09-21T22:16:38.153000+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': 'Rasen mähen und die Pflanzen gießen.',
'priority': 1,
'repeat': dict({
'f': False,
'm': True,
's': False,
'su': False,
't': True,
'th': False,
'w': True,
}),
'text': 'Garten pflegen',
'type': 'todo',
}),
'2f6fcabc-f670-4ec3-ba65-817e8deea490': dict({
'challenge': dict({
'broken': None,
'id': None,
'shortName': None,
'taskId': None,
'winner': None,
}),
'created_at': '2024-09-21T22:17:19.513000+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': 'Strom- und Internetrechnungen rechtzeitig überweisen.',
'priority': 1,
'repeat': dict({
'f': False,
'm': True,
's': False,
'su': False,
't': True,
'th': False,
'w': True,
}),
'text': 'Rechnungen bezahlen',
'type': 'todo',
}),
'86ea2475-d1b5-4020-bdcc-c188c7996afa': dict({
'challenge': dict({
'broken': None,
'id': None,
'shortName': None,
'taskId': None,
'winner': None,
}),
'created_at': '2024-09-21T22:16:16.756000+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': 'Den Ausflug für das kommende Wochenende organisieren.',
'priority': 1,
'repeat': dict({
'f': False,
'm': True,
's': False,
'su': False,
't': True,
'th': False,
'w': True,
}),
'tags': list([
'51076966-2970-4b40-b6ba-d58c6a756dd7',
]),
'text': 'Wochenendausflug planen',
'type': 'todo',
}),
'88de7cd9-af2b-49ce-9afd-bf941d87336b': dict({
'challenge': dict({
'broken': None,
'id': None,
'shortName': None,
'taskId': None,
'winner': None,
}),
'created_at': '2024-09-21T22:17:57.816000+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': 'Das Buch, das du angefangen hast, bis zum Wochenende fertig lesen.',
'priority': 1,
'repeat': dict({
'f': False,
'm': True,
's': False,
'su': False,
't': True,
'th': False,
'w': True,
}),
'tags': list([
'20409521-c096-447f-9a90-23e8da615710',
'8515e4ae-2f4b-455a-b4a4-8939e04b1bfd',
]),
'text': 'Buch zu Ende lesen',
'type': 'todo',
}),
'friendly_name': "test-user To-Do's",
'unit_of_measurement': 'tasks',
}),
'context': <ANY>,
'entity_id': 'sensor.test_user_to_do_s',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '4',
})
# ---

View File

@ -6,12 +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.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
@ -42,31 +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.usefixtures("habitica", "entity_registry_enabled_by_default")
async def test_sensor_deprecation_issue(
hass: HomeAssistant,
config_entry: MockConfigEntry,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test task sensor deprecation issue."""
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_task_entity_{HabiticaSensorEntity.TODOS}",
)
assert issue_registry.async_get_issue(
domain=DOMAIN,
issue_id=f"deprecated_task_entity_{HabiticaSensorEntity.DAILIES}",
)