Skip to content

Commit

Permalink
Remove deprecated sensors in Habitica integration (home-assistant#134320
Browse files Browse the repository at this point in the history
)

* Remove deprecated sensors

* remove todos/dailies also from enum
  • Loading branch information
tr4nt0r authored Jan 3, 2025
1 parent 336af8b commit 9320ccf
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 579 deletions.
6 changes: 0 additions & 6 deletions homeassistant/components/habitica/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@
"rogue": "mdi:ninja"
}
},
"todos": {
"default": "mdi:checkbox-outline"
},
"dailys": {
"default": "mdi:calendar-month"
},
"habits": {
"default": "mdi:contrast-box"
},
Expand Down
65 changes: 3 additions & 62 deletions homeassistant/components/habitica/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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,
Expand All @@ -18,25 +18,18 @@
)

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__)

Expand Down Expand Up @@ -73,8 +66,6 @@ class HabiticaSensorEntity(StrEnum):
GOLD = "gold"
CLASS = "class"
HABITS = "habits"
DAILIES = "dailys"
TODOS = "todos"
REWARDS = "rewards"
GEMS = "gems"
TRINKETS = "trinkets"
Expand Down Expand Up @@ -227,22 +218,6 @@ class HabiticaSensorEntity(StrEnum):
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,
Expand Down Expand Up @@ -324,37 +299,3 @@ def extra_state_attributes(self) -> Mapping[str, Any] | None:
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()
12 changes: 0 additions & 12 deletions homeassistant/components/habitica/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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%]"
Expand Down Expand Up @@ -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."
Expand Down
Loading

0 comments on commit 9320ccf

Please sign in to comment.