Add entity categories to esphome (#58495)

This commit is contained in:
Jesse Hills 2021-10-27 12:53:39 +13:00 committed by GitHub
parent e2e19cf4b4
commit c656bf1646
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 3 deletions

View File

@ -13,6 +13,7 @@ from aioesphomeapi import (
APIIntEnum,
APIVersion,
DeviceInfo as EsphomeDeviceInfo,
EntityCategory,
EntityInfo,
EntityState,
HomeassistantServiceCall,
@ -32,6 +33,8 @@ from homeassistant.const import (
CONF_MODE,
CONF_PASSWORD,
CONF_PORT,
ENTITY_CATEGORY_CONFIG,
ENTITY_CATEGORY_DIAGNOSTIC,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import Event, HomeAssistant, ServiceCall, State, callback
@ -640,6 +643,15 @@ class EsphomeEnumMapper(Generic[_EnumT, _ValT]):
ICON_SCHEMA = vol.Schema(cv.icon)
ENTITY_CATEGORIES: EsphomeEnumMapper[EntityCategory, str | None] = EsphomeEnumMapper(
{
EntityCategory.NONE: None,
EntityCategory.CONFIG: ENTITY_CATEGORY_CONFIG,
EntityCategory.DIAGNOSTIC: ENTITY_CATEGORY_DIAGNOSTIC,
}
)
class EsphomeEntity(Entity, Generic[_InfoT, _StateT]):
"""Define a base esphome entity."""
@ -781,3 +793,10 @@ class EsphomeEntity(Entity, Generic[_InfoT, _StateT]):
def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added to the entity registry."""
return not self._static_info.disabled_by_default
@property
def entity_category(self) -> str | None:
"""Return the category of the entity, if any."""
if not self._static_info.entity_category:
return None
return ENTITY_CATEGORIES.from_esphome(self._static_info.entity_category)

View File

@ -3,7 +3,7 @@
"name": "ESPHome",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/esphome",
"requirements": ["aioesphomeapi==10.0.0"],
"requirements": ["aioesphomeapi==10.1.0"],
"zeroconf": ["_esphomelib._tcp.local."],
"codeowners": ["@OttoWinter", "@jesserockz"],
"after_dependencies": ["zeroconf", "tag"],

View File

@ -161,7 +161,7 @@ aioeagle==1.1.0
aioemonitor==1.0.5
# homeassistant.components.esphome
aioesphomeapi==10.0.0
aioesphomeapi==10.1.0
# homeassistant.components.flo
aioflo==0.4.1

View File

@ -109,7 +109,7 @@ aioeagle==1.1.0
aioemonitor==1.0.5
# homeassistant.components.esphome
aioesphomeapi==10.0.0
aioesphomeapi==10.1.0
# homeassistant.components.flo
aioflo==0.4.1