mirror of
https://github.com/home-assistant/core.git
synced 2025-08-05 13:45:12 +02:00
Change sensor names
This commit is contained in:
@@ -1,40 +1,37 @@
|
|||||||
{
|
{
|
||||||
"services": {
|
|
||||||
"api_call": "mdi:console"
|
|
||||||
},
|
|
||||||
"entity": {
|
"entity": {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
"name": {
|
"display_name": {
|
||||||
"default": "mdi:account-circle"
|
"default": "mdi:account-circle"
|
||||||
},
|
},
|
||||||
"hp": {
|
"health": {
|
||||||
"default": "mdi:heart",
|
"default": "mdi:heart",
|
||||||
"state": {
|
"state": {
|
||||||
"0": "mdi:skull-outline"
|
"0": "mdi:skull-outline"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"maxhealth": {
|
"health_max": {
|
||||||
"default": "mdi:heart"
|
"default": "mdi:heart"
|
||||||
},
|
},
|
||||||
"mp": {
|
"mana": {
|
||||||
"default": "mdi:flask",
|
"default": "mdi:flask",
|
||||||
"state": {
|
"state": {
|
||||||
"0": "mdi:flask-empty-outline"
|
"0": "mdi:flask-empty-outline"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"maxmp": {
|
"mana_max": {
|
||||||
"default": "mdi:flask"
|
"default": "mdi:flask"
|
||||||
},
|
},
|
||||||
"exp": {
|
"experience": {
|
||||||
"default": "mdi:star-four-points"
|
"default": "mdi:star-four-points"
|
||||||
},
|
},
|
||||||
"tonextlevel": {
|
"experience_max": {
|
||||||
"default": "mdi:star-four-points"
|
"default": "mdi:star-four-points"
|
||||||
},
|
},
|
||||||
"lvl": {
|
"level": {
|
||||||
"default": "mdi:crown-circle"
|
"default": "mdi:crown-circle"
|
||||||
},
|
},
|
||||||
"gp": {
|
"gold": {
|
||||||
"default": "mdi:sack"
|
"default": "mdi:sack"
|
||||||
},
|
},
|
||||||
"class": {
|
"class": {
|
||||||
@@ -47,5 +44,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"services": {
|
||||||
|
"api_call": "mdi:console"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,12 +5,18 @@ from __future__ import annotations
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from enum import StrEnum
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
import logging
|
import logging
|
||||||
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from aiohttp import ClientResponseError
|
from aiohttp import ClientResponseError
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
from homeassistant.components.sensor import (
|
||||||
|
SensorDeviceClass,
|
||||||
|
SensorEntity,
|
||||||
|
SensorEntityDescription,
|
||||||
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_NAME, CONF_URL
|
from homeassistant.const import CONF_NAME, CONF_URL
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@@ -49,67 +55,83 @@ class HabitipySensorEntityDescription(SensorEntityDescription):
|
|||||||
value_path: list[str]
|
value_path: list[str]
|
||||||
|
|
||||||
|
|
||||||
|
class HabitipySensorEntity(StrEnum):
|
||||||
|
"""Habitipy Entities."""
|
||||||
|
|
||||||
|
DISPLAY_NAME = "display_name"
|
||||||
|
HEALTH = "health"
|
||||||
|
HEALTH_MAX = "health_max"
|
||||||
|
MANA = "mana"
|
||||||
|
MANA_MAX = "mana_max"
|
||||||
|
EXPERIENCE = "experience"
|
||||||
|
EXPERIENCE_MAX = "experience_max"
|
||||||
|
LEVEL = "level"
|
||||||
|
GOLD = "gold"
|
||||||
|
CLASS = "class"
|
||||||
|
|
||||||
|
|
||||||
SENSOR_DESCRIPTIONS: dict[str, HabitipySensorEntityDescription] = {
|
SENSOR_DESCRIPTIONS: dict[str, HabitipySensorEntityDescription] = {
|
||||||
"name": HabitipySensorEntityDescription(
|
HabitipySensorEntity.DISPLAY_NAME: HabitipySensorEntityDescription(
|
||||||
key="name",
|
key=HabitipySensorEntity.DISPLAY_NAME,
|
||||||
translation_key="name",
|
translation_key=HabitipySensorEntity.DISPLAY_NAME,
|
||||||
value_path=["profile", "name"],
|
value_path=["profile", "name"],
|
||||||
),
|
),
|
||||||
"hp": HabitipySensorEntityDescription(
|
HabitipySensorEntity.HEALTH: HabitipySensorEntityDescription(
|
||||||
key="hp",
|
key=HabitipySensorEntity.HEALTH,
|
||||||
translation_key="hp",
|
translation_key=HabitipySensorEntity.HEALTH,
|
||||||
native_unit_of_measurement="HP",
|
native_unit_of_measurement="HP",
|
||||||
suggested_display_precision=0,
|
suggested_display_precision=0,
|
||||||
value_path=["stats", "hp"],
|
value_path=["stats", "hp"],
|
||||||
),
|
),
|
||||||
"maxHealth": HabitipySensorEntityDescription(
|
HabitipySensorEntity.HEALTH_MAX: HabitipySensorEntityDescription(
|
||||||
key="maxHealth",
|
key=HabitipySensorEntity.HEALTH_MAX,
|
||||||
translation_key="maxhealth",
|
translation_key=HabitipySensorEntity.HEALTH_MAX,
|
||||||
native_unit_of_measurement="HP",
|
native_unit_of_measurement="HP",
|
||||||
value_path=["stats", "maxHealth"],
|
value_path=["stats", "maxHealth"],
|
||||||
),
|
),
|
||||||
"mp": HabitipySensorEntityDescription(
|
HabitipySensorEntity.MANA: HabitipySensorEntityDescription(
|
||||||
key="mp",
|
key=HabitipySensorEntity.MANA,
|
||||||
translation_key="mp",
|
translation_key=HabitipySensorEntity.MANA,
|
||||||
native_unit_of_measurement="MP",
|
native_unit_of_measurement="MP",
|
||||||
suggested_display_precision=0,
|
suggested_display_precision=0,
|
||||||
value_path=["stats", "mp"],
|
value_path=["stats", "mp"],
|
||||||
),
|
),
|
||||||
"maxMP": HabitipySensorEntityDescription(
|
HabitipySensorEntity.MANA_MAX: HabitipySensorEntityDescription(
|
||||||
key="maxMP",
|
key=HabitipySensorEntity.MANA_MAX,
|
||||||
translation_key="maxmp",
|
translation_key=HabitipySensorEntity.MANA_MAX,
|
||||||
native_unit_of_measurement="MP",
|
native_unit_of_measurement="MP",
|
||||||
value_path=["stats", "maxMP"],
|
value_path=["stats", "maxMP"],
|
||||||
),
|
),
|
||||||
"exp": HabitipySensorEntityDescription(
|
HabitipySensorEntity.EXPERIENCE: HabitipySensorEntityDescription(
|
||||||
key="exp",
|
key=HabitipySensorEntity.EXPERIENCE,
|
||||||
translation_key="exp",
|
translation_key=HabitipySensorEntity.EXPERIENCE,
|
||||||
native_unit_of_measurement="XP",
|
native_unit_of_measurement="XP",
|
||||||
value_path=["stats", "exp"],
|
value_path=["stats", "exp"],
|
||||||
),
|
),
|
||||||
"toNextLevel": HabitipySensorEntityDescription(
|
HabitipySensorEntity.EXPERIENCE_MAX: HabitipySensorEntityDescription(
|
||||||
key="toNextLevel",
|
key=HabitipySensorEntity.EXPERIENCE_MAX,
|
||||||
translation_key="tonextlevel",
|
translation_key=HabitipySensorEntity.EXPERIENCE_MAX,
|
||||||
native_unit_of_measurement="XP",
|
native_unit_of_measurement="XP",
|
||||||
value_path=["stats", "toNextLevel"],
|
value_path=["stats", "toNextLevel"],
|
||||||
),
|
),
|
||||||
"lvl": HabitipySensorEntityDescription(
|
HabitipySensorEntity.LEVEL: HabitipySensorEntityDescription(
|
||||||
key="lvl",
|
key=HabitipySensorEntity.LEVEL,
|
||||||
translation_key="lvl",
|
translation_key=HabitipySensorEntity.LEVEL,
|
||||||
native_unit_of_measurement="Lvl",
|
|
||||||
value_path=["stats", "lvl"],
|
value_path=["stats", "lvl"],
|
||||||
),
|
),
|
||||||
"gp": HabitipySensorEntityDescription(
|
HabitipySensorEntity.GOLD: HabitipySensorEntityDescription(
|
||||||
key="gp",
|
key=HabitipySensorEntity.GOLD,
|
||||||
translation_key="gp",
|
translation_key=HabitipySensorEntity.GOLD,
|
||||||
native_unit_of_measurement="🜚", # alchemy symbol for gold
|
native_unit_of_measurement="GP",
|
||||||
suggested_display_precision=2,
|
suggested_display_precision=2,
|
||||||
value_path=["stats", "gp"],
|
value_path=["stats", "gp"],
|
||||||
),
|
),
|
||||||
"class": HabitipySensorEntityDescription(
|
HabitipySensorEntity.CLASS: HabitipySensorEntityDescription(
|
||||||
key="class",
|
key=HabitipySensorEntity.CLASS,
|
||||||
translation_key="class",
|
translation_key=HabitipySensorEntity.CLASS,
|
||||||
value_path=["stats", "class"],
|
value_path=["stats", "class"],
|
||||||
|
device_class=SensorDeviceClass.ENUM,
|
||||||
|
options=["warrior", "healer", "wizard", "rogue"],
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +200,9 @@ async def async_setup_entry(
|
|||||||
class HabitipyData:
|
class HabitipyData:
|
||||||
"""Habitica API user data cache."""
|
"""Habitica API user data cache."""
|
||||||
|
|
||||||
def __init__(self, api):
|
tasks: dict[str, Any]
|
||||||
|
|
||||||
|
def __init__(self, api) -> None:
|
||||||
"""Habitica API user data cache."""
|
"""Habitica API user data cache."""
|
||||||
self.api = api
|
self.api = api
|
||||||
self.data = None
|
self.data = None
|
||||||
@@ -233,14 +257,15 @@ class HabitipySensor(SensorEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
updater,
|
coordinator,
|
||||||
entity_description: HabitipySensorEntityDescription,
|
entity_description: HabitipySensorEntityDescription,
|
||||||
entry: ConfigEntry,
|
entry: ConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize a generic Habitica sensor."""
|
"""Initialize a generic Habitica sensor."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
assert entry.unique_id
|
if TYPE_CHECKING:
|
||||||
self._updater = updater
|
assert entry.unique_id
|
||||||
|
self.coordinator = coordinator
|
||||||
self.entity_description = entity_description
|
self.entity_description = entity_description
|
||||||
self._attr_unique_id = f"{entry.unique_id}_{entity_description.key}"
|
self._attr_unique_id = f"{entry.unique_id}_{entity_description.key}"
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
@@ -253,9 +278,9 @@ class HabitipySensor(SensorEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Update Condition and Forecast."""
|
"""Update Sensor state."""
|
||||||
await self._updater.update()
|
await self.coordinator.update()
|
||||||
data = self._updater.data
|
data = self.coordinator.data
|
||||||
for element in self.entity_description.value_path:
|
for element in self.entity_description.value_path:
|
||||||
data = data[element]
|
data = data[element]
|
||||||
self._attr_native_value = data
|
self._attr_native_value = data
|
||||||
|
@@ -19,6 +19,46 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"entity": {
|
||||||
|
"sensor": {
|
||||||
|
"display_name": {
|
||||||
|
"name": "Display name"
|
||||||
|
},
|
||||||
|
"health": {
|
||||||
|
"name": "Health"
|
||||||
|
},
|
||||||
|
"health_max": {
|
||||||
|
"name": "Health max."
|
||||||
|
},
|
||||||
|
"mana": {
|
||||||
|
"name": "Mana"
|
||||||
|
},
|
||||||
|
"mana_max": {
|
||||||
|
"name": "Mana max."
|
||||||
|
},
|
||||||
|
"experience": {
|
||||||
|
"name": "Experience"
|
||||||
|
},
|
||||||
|
"experience_max": {
|
||||||
|
"name": "Next Level"
|
||||||
|
},
|
||||||
|
"level": {
|
||||||
|
"name": "Level"
|
||||||
|
},
|
||||||
|
"gold": {
|
||||||
|
"name": "Gold"
|
||||||
|
},
|
||||||
|
"class": {
|
||||||
|
"name": "Class",
|
||||||
|
"state": {
|
||||||
|
"warrior": "Warrior",
|
||||||
|
"healer": "Healer",
|
||||||
|
"wizard": "Mage",
|
||||||
|
"rogue": "Rogue"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"services": {
|
"services": {
|
||||||
"api_call": {
|
"api_call": {
|
||||||
"name": "API name",
|
"name": "API name",
|
||||||
@@ -38,45 +78,5 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"entity": {
|
|
||||||
"sensor": {
|
|
||||||
"name": {
|
|
||||||
"name": "Display name"
|
|
||||||
},
|
|
||||||
"hp": {
|
|
||||||
"name": "Health"
|
|
||||||
},
|
|
||||||
"maxhealth": {
|
|
||||||
"name": "Health max."
|
|
||||||
},
|
|
||||||
"mp": {
|
|
||||||
"name": "Mana"
|
|
||||||
},
|
|
||||||
"maxmp": {
|
|
||||||
"name": "Mana max."
|
|
||||||
},
|
|
||||||
"exp": {
|
|
||||||
"name": "Experience"
|
|
||||||
},
|
|
||||||
"tonextlevel": {
|
|
||||||
"name": "Next Level"
|
|
||||||
},
|
|
||||||
"lvl": {
|
|
||||||
"name": "Level"
|
|
||||||
},
|
|
||||||
"gp": {
|
|
||||||
"name": "Gold"
|
|
||||||
},
|
|
||||||
"class": {
|
|
||||||
"name": "Class",
|
|
||||||
"state": {
|
|
||||||
"warrior": "Warrior",
|
|
||||||
"healer": "Healer",
|
|
||||||
"wizard": "Mage",
|
|
||||||
"rogue": "Rogue"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user