Add Entity categories for Home Assistant (#2636)

This commit is contained in:
Jesse Hills 2021-11-08 07:24:52 +13:00 committed by GitHub
parent b450d4c734
commit 3c0414c420
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 354 additions and 14 deletions

View file

@ -81,4 +81,5 @@ from esphome.cpp_types import ( # noqa
GPIOPin, GPIOPin,
InternalGPIOPin, InternalGPIOPin,
gpio_Flags, gpio_Flags,
EntityCategory,
) )

View file

@ -4,7 +4,8 @@ from esphome.components import sensor, ble_client
from esphome.const import ( from esphome.const import (
CONF_ID, CONF_ID,
CONF_BATTERY_LEVEL, CONF_BATTERY_LEVEL,
ICON_BATTERY, DEVICE_CLASS_BATTERY,
ENTITY_CATEGORY_DIAGNOSTIC,
CONF_ILLUMINANCE, CONF_ILLUMINANCE,
ICON_BRIGHTNESS_5, ICON_BRIGHTNESS_5,
UNIT_PERCENT, UNIT_PERCENT,
@ -20,10 +21,15 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(Am43), cv.GenerateID(): cv.declare_id(Am43),
cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema( cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(
UNIT_PERCENT, ICON_BATTERY, 0 unit_of_measurement=UNIT_PERCENT,
device_class=DEVICE_CLASS_BATTERY,
accuracy_decimals=0,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_ILLUMINANCE): sensor.sensor_schema( cv.Optional(CONF_ILLUMINANCE): sensor.sensor_schema(
UNIT_PERCENT, ICON_BRIGHTNESS_5, 0 unit_of_measurement=UNIT_PERCENT,
icon=ICON_BRIGHTNESS_5,
accuracy_decimals=0,
), ),
} }
) )

View file

@ -203,6 +203,14 @@ message SubscribeStatesRequest {
// Empty // Empty
} }
// ==================== COMMON =====================
enum EntityCategory {
ENTITY_CATEGORY_NONE = 0;
ENTITY_CATEGORY_CONFIG = 1;
ENTITY_CATEGORY_DIAGNOSTIC = 2;
}
// ==================== BINARY SENSOR ==================== // ==================== BINARY SENSOR ====================
message ListEntitiesBinarySensorResponse { message ListEntitiesBinarySensorResponse {
option (id) = 12; option (id) = 12;
@ -218,6 +226,7 @@ message ListEntitiesBinarySensorResponse {
bool is_status_binary_sensor = 6; bool is_status_binary_sensor = 6;
bool disabled_by_default = 7; bool disabled_by_default = 7;
string icon = 8; string icon = 8;
EntityCategory entity_category = 9;
} }
message BinarySensorStateResponse { message BinarySensorStateResponse {
option (id) = 21; option (id) = 21;
@ -249,6 +258,7 @@ message ListEntitiesCoverResponse {
string device_class = 8; string device_class = 8;
bool disabled_by_default = 9; bool disabled_by_default = 9;
string icon = 10; string icon = 10;
EntityCategory entity_category = 11;
} }
enum LegacyCoverState { enum LegacyCoverState {
@ -318,6 +328,7 @@ message ListEntitiesFanResponse {
int32 supported_speed_count = 8; int32 supported_speed_count = 8;
bool disabled_by_default = 9; bool disabled_by_default = 9;
string icon = 10; string icon = 10;
EntityCategory entity_category = 11;
} }
enum FanSpeed { enum FanSpeed {
FAN_SPEED_LOW = 0; FAN_SPEED_LOW = 0;
@ -394,6 +405,7 @@ message ListEntitiesLightResponse {
repeated string effects = 11; repeated string effects = 11;
bool disabled_by_default = 13; bool disabled_by_default = 13;
string icon = 14; string icon = 14;
EntityCategory entity_category = 15;
} }
message LightStateResponse { message LightStateResponse {
option (id) = 24; option (id) = 24;
@ -482,6 +494,7 @@ message ListEntitiesSensorResponse {
// Last reset type removed in 2021.9.0 // Last reset type removed in 2021.9.0
SensorLastResetType legacy_last_reset_type = 11; SensorLastResetType legacy_last_reset_type = 11;
bool disabled_by_default = 12; bool disabled_by_default = 12;
EntityCategory entity_category = 13;
} }
message SensorStateResponse { message SensorStateResponse {
option (id) = 25; option (id) = 25;
@ -510,6 +523,7 @@ message ListEntitiesSwitchResponse {
string icon = 5; string icon = 5;
bool assumed_state = 6; bool assumed_state = 6;
bool disabled_by_default = 7; bool disabled_by_default = 7;
EntityCategory entity_category = 8;
} }
message SwitchStateResponse { message SwitchStateResponse {
option (id) = 26; option (id) = 26;
@ -543,6 +557,7 @@ message ListEntitiesTextSensorResponse {
string icon = 5; string icon = 5;
bool disabled_by_default = 6; bool disabled_by_default = 6;
EntityCategory entity_category = 7;
} }
message TextSensorStateResponse { message TextSensorStateResponse {
option (id) = 27; option (id) = 27;
@ -704,6 +719,7 @@ message ListEntitiesCameraResponse {
string unique_id = 4; string unique_id = 4;
bool disabled_by_default = 5; bool disabled_by_default = 5;
string icon = 6; string icon = 6;
EntityCategory entity_category = 7;
} }
message CameraImageResponse { message CameraImageResponse {
@ -798,6 +814,7 @@ message ListEntitiesClimateResponse {
repeated string supported_custom_presets = 17; repeated string supported_custom_presets = 17;
bool disabled_by_default = 18; bool disabled_by_default = 18;
string icon = 19; string icon = 19;
EntityCategory entity_category = 20;
} }
message ClimateStateResponse { message ClimateStateResponse {
option (id) = 47; option (id) = 47;
@ -866,6 +883,7 @@ message ListEntitiesNumberResponse {
float max_value = 7; float max_value = 7;
float step = 8; float step = 8;
bool disabled_by_default = 9; bool disabled_by_default = 9;
EntityCategory entity_category = 10;
} }
message NumberStateResponse { message NumberStateResponse {
option (id) = 50; option (id) = 50;
@ -903,6 +921,7 @@ message ListEntitiesSelectResponse {
string icon = 5; string icon = 5;
repeated string options = 6; repeated string options = 6;
bool disabled_by_default = 7; bool disabled_by_default = 7;
EntityCategory entity_category = 8;
} }
message SelectStateResponse { message SelectStateResponse {
option (id) = 53; option (id) = 53;

View file

@ -184,6 +184,7 @@ bool APIConnection::send_binary_sensor_info(binary_sensor::BinarySensor *binary_
msg.is_status_binary_sensor = binary_sensor->is_status_binary_sensor(); msg.is_status_binary_sensor = binary_sensor->is_status_binary_sensor();
msg.disabled_by_default = binary_sensor->is_disabled_by_default(); msg.disabled_by_default = binary_sensor->is_disabled_by_default();
msg.icon = binary_sensor->get_icon(); msg.icon = binary_sensor->get_icon();
msg.entity_category = static_cast<enums::EntityCategory>(binary_sensor->get_entity_category());
return this->send_list_entities_binary_sensor_response(msg); return this->send_list_entities_binary_sensor_response(msg);
} }
#endif #endif
@ -217,6 +218,7 @@ bool APIConnection::send_cover_info(cover::Cover *cover) {
msg.device_class = cover->get_device_class(); msg.device_class = cover->get_device_class();
msg.disabled_by_default = cover->is_disabled_by_default(); msg.disabled_by_default = cover->is_disabled_by_default();
msg.icon = cover->get_icon(); msg.icon = cover->get_icon();
msg.entity_category = static_cast<enums::EntityCategory>(cover->get_entity_category());
return this->send_list_entities_cover_response(msg); return this->send_list_entities_cover_response(msg);
} }
void APIConnection::cover_command(const CoverCommandRequest &msg) { void APIConnection::cover_command(const CoverCommandRequest &msg) {
@ -283,6 +285,7 @@ bool APIConnection::send_fan_info(fan::FanState *fan) {
msg.supported_speed_count = traits.supported_speed_count(); msg.supported_speed_count = traits.supported_speed_count();
msg.disabled_by_default = fan->is_disabled_by_default(); msg.disabled_by_default = fan->is_disabled_by_default();
msg.icon = fan->get_icon(); msg.icon = fan->get_icon();
msg.entity_category = static_cast<enums::EntityCategory>(fan->get_entity_category());
return this->send_list_entities_fan_response(msg); return this->send_list_entities_fan_response(msg);
} }
void APIConnection::fan_command(const FanCommandRequest &msg) { void APIConnection::fan_command(const FanCommandRequest &msg) {
@ -346,6 +349,7 @@ bool APIConnection::send_light_info(light::LightState *light) {
msg.disabled_by_default = light->is_disabled_by_default(); msg.disabled_by_default = light->is_disabled_by_default();
msg.icon = light->get_icon(); msg.icon = light->get_icon();
msg.entity_category = static_cast<enums::EntityCategory>(light->get_entity_category());
for (auto mode : traits.get_supported_color_modes()) for (auto mode : traits.get_supported_color_modes())
msg.supported_color_modes.push_back(static_cast<enums::ColorMode>(mode)); msg.supported_color_modes.push_back(static_cast<enums::ColorMode>(mode));
@ -432,7 +436,7 @@ bool APIConnection::send_sensor_info(sensor::Sensor *sensor) {
msg.device_class = sensor->get_device_class(); msg.device_class = sensor->get_device_class();
msg.state_class = static_cast<enums::SensorStateClass>(sensor->get_state_class()); msg.state_class = static_cast<enums::SensorStateClass>(sensor->get_state_class());
msg.disabled_by_default = sensor->is_disabled_by_default(); msg.disabled_by_default = sensor->is_disabled_by_default();
msg.entity_category = static_cast<enums::EntityCategory>(sensor->get_entity_category());
return this->send_list_entities_sensor_response(msg); return this->send_list_entities_sensor_response(msg);
} }
#endif #endif
@ -456,6 +460,7 @@ bool APIConnection::send_switch_info(switch_::Switch *a_switch) {
msg.icon = a_switch->get_icon(); msg.icon = a_switch->get_icon();
msg.assumed_state = a_switch->assumed_state(); msg.assumed_state = a_switch->assumed_state();
msg.disabled_by_default = a_switch->is_disabled_by_default(); msg.disabled_by_default = a_switch->is_disabled_by_default();
msg.entity_category = static_cast<enums::EntityCategory>(a_switch->get_entity_category());
return this->send_list_entities_switch_response(msg); return this->send_list_entities_switch_response(msg);
} }
void APIConnection::switch_command(const SwitchCommandRequest &msg) { void APIConnection::switch_command(const SwitchCommandRequest &msg) {
@ -491,6 +496,7 @@ bool APIConnection::send_text_sensor_info(text_sensor::TextSensor *text_sensor)
msg.unique_id = get_default_unique_id("text_sensor", text_sensor); msg.unique_id = get_default_unique_id("text_sensor", text_sensor);
msg.icon = text_sensor->get_icon(); msg.icon = text_sensor->get_icon();
msg.disabled_by_default = text_sensor->is_disabled_by_default(); msg.disabled_by_default = text_sensor->is_disabled_by_default();
msg.entity_category = static_cast<enums::EntityCategory>(text_sensor->get_entity_category());
return this->send_list_entities_text_sensor_response(msg); return this->send_list_entities_text_sensor_response(msg);
} }
#endif #endif
@ -537,6 +543,7 @@ bool APIConnection::send_climate_info(climate::Climate *climate) {
msg.disabled_by_default = climate->is_disabled_by_default(); msg.disabled_by_default = climate->is_disabled_by_default();
msg.icon = climate->get_icon(); msg.icon = climate->get_icon();
msg.entity_category = static_cast<enums::EntityCategory>(climate->get_entity_category());
msg.supports_current_temperature = traits.get_supports_current_temperature(); msg.supports_current_temperature = traits.get_supports_current_temperature();
msg.supports_two_point_target_temperature = traits.get_supports_two_point_target_temperature(); msg.supports_two_point_target_temperature = traits.get_supports_two_point_target_temperature();
@ -611,6 +618,7 @@ bool APIConnection::send_number_info(number::Number *number) {
msg.unique_id = get_default_unique_id("number", number); msg.unique_id = get_default_unique_id("number", number);
msg.icon = number->get_icon(); msg.icon = number->get_icon();
msg.disabled_by_default = number->is_disabled_by_default(); msg.disabled_by_default = number->is_disabled_by_default();
msg.entity_category = static_cast<enums::EntityCategory>(number->get_entity_category());
msg.min_value = number->traits.get_min_value(); msg.min_value = number->traits.get_min_value();
msg.max_value = number->traits.get_max_value(); msg.max_value = number->traits.get_max_value();
@ -648,6 +656,7 @@ bool APIConnection::send_select_info(select::Select *select) {
msg.unique_id = get_default_unique_id("select", select); msg.unique_id = get_default_unique_id("select", select);
msg.icon = select->get_icon(); msg.icon = select->get_icon();
msg.disabled_by_default = select->is_disabled_by_default(); msg.disabled_by_default = select->is_disabled_by_default();
msg.entity_category = static_cast<enums::EntityCategory>(select->get_entity_category());
for (const auto &option : select->traits.get_options()) for (const auto &option : select->traits.get_options())
msg.options.push_back(option); msg.options.push_back(option);
@ -681,6 +690,7 @@ bool APIConnection::send_camera_info(esp32_camera::ESP32Camera *camera) {
msg.unique_id = get_default_unique_id("camera", camera); msg.unique_id = get_default_unique_id("camera", camera);
msg.disabled_by_default = camera->is_disabled_by_default(); msg.disabled_by_default = camera->is_disabled_by_default();
msg.icon = camera->get_icon(); msg.icon = camera->get_icon();
msg.entity_category = static_cast<enums::EntityCategory>(camera->get_entity_category());
return this->send_list_entities_camera_response(msg); return this->send_list_entities_camera_response(msg);
} }
void APIConnection::camera_image(const CameraImageRequest &msg) { void APIConnection::camera_image(const CameraImageRequest &msg) {

View file

@ -6,6 +6,18 @@
namespace esphome { namespace esphome {
namespace api { namespace api {
template<> const char *proto_enum_to_string<enums::EntityCategory>(enums::EntityCategory value) {
switch (value) {
case enums::ENTITY_CATEGORY_NONE:
return "ENTITY_CATEGORY_NONE";
case enums::ENTITY_CATEGORY_CONFIG:
return "ENTITY_CATEGORY_CONFIG";
case enums::ENTITY_CATEGORY_DIAGNOSTIC:
return "ENTITY_CATEGORY_DIAGNOSTIC";
default:
return "UNKNOWN";
}
}
template<> const char *proto_enum_to_string<enums::LegacyCoverState>(enums::LegacyCoverState value) { template<> const char *proto_enum_to_string<enums::LegacyCoverState>(enums::LegacyCoverState value) {
switch (value) { switch (value) {
case enums::LEGACY_COVER_STATE_OPEN: case enums::LEGACY_COVER_STATE_OPEN:
@ -519,6 +531,10 @@ bool ListEntitiesBinarySensorResponse::decode_varint(uint32_t field_id, ProtoVar
this->disabled_by_default = value.as_bool(); this->disabled_by_default = value.as_bool();
return true; return true;
} }
case 9: {
this->entity_category = value.as_enum<enums::EntityCategory>();
return true;
}
default: default:
return false; return false;
} }
@ -568,6 +584,7 @@ void ListEntitiesBinarySensorResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_bool(6, this->is_status_binary_sensor); buffer.encode_bool(6, this->is_status_binary_sensor);
buffer.encode_bool(7, this->disabled_by_default); buffer.encode_bool(7, this->disabled_by_default);
buffer.encode_string(8, this->icon); buffer.encode_string(8, this->icon);
buffer.encode_enum<enums::EntityCategory>(9, this->entity_category);
} }
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void ListEntitiesBinarySensorResponse::dump_to(std::string &out) const { void ListEntitiesBinarySensorResponse::dump_to(std::string &out) const {
@ -605,6 +622,10 @@ void ListEntitiesBinarySensorResponse::dump_to(std::string &out) const {
out.append(" icon: "); out.append(" icon: ");
out.append("'").append(this->icon).append("'"); out.append("'").append(this->icon).append("'");
out.append("\n"); out.append("\n");
out.append(" entity_category: ");
out.append(proto_enum_to_string<enums::EntityCategory>(this->entity_category));
out.append("\n");
out.append("}"); out.append("}");
} }
#endif #endif
@ -674,6 +695,10 @@ bool ListEntitiesCoverResponse::decode_varint(uint32_t field_id, ProtoVarInt val
this->disabled_by_default = value.as_bool(); this->disabled_by_default = value.as_bool();
return true; return true;
} }
case 11: {
this->entity_category = value.as_enum<enums::EntityCategory>();
return true;
}
default: default:
return false; return false;
} }
@ -725,6 +750,7 @@ void ListEntitiesCoverResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_string(8, this->device_class); buffer.encode_string(8, this->device_class);
buffer.encode_bool(9, this->disabled_by_default); buffer.encode_bool(9, this->disabled_by_default);
buffer.encode_string(10, this->icon); buffer.encode_string(10, this->icon);
buffer.encode_enum<enums::EntityCategory>(11, this->entity_category);
} }
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void ListEntitiesCoverResponse::dump_to(std::string &out) const { void ListEntitiesCoverResponse::dump_to(std::string &out) const {
@ -770,6 +796,10 @@ void ListEntitiesCoverResponse::dump_to(std::string &out) const {
out.append(" icon: "); out.append(" icon: ");
out.append("'").append(this->icon).append("'"); out.append("'").append(this->icon).append("'");
out.append("\n"); out.append("\n");
out.append(" entity_category: ");
out.append(proto_enum_to_string<enums::EntityCategory>(this->entity_category));
out.append("\n");
out.append("}"); out.append("}");
} }
#endif #endif
@ -958,6 +988,10 @@ bool ListEntitiesFanResponse::decode_varint(uint32_t field_id, ProtoVarInt value
this->disabled_by_default = value.as_bool(); this->disabled_by_default = value.as_bool();
return true; return true;
} }
case 11: {
this->entity_category = value.as_enum<enums::EntityCategory>();
return true;
}
default: default:
return false; return false;
} }
@ -1005,6 +1039,7 @@ void ListEntitiesFanResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_int32(8, this->supported_speed_count); buffer.encode_int32(8, this->supported_speed_count);
buffer.encode_bool(9, this->disabled_by_default); buffer.encode_bool(9, this->disabled_by_default);
buffer.encode_string(10, this->icon); buffer.encode_string(10, this->icon);
buffer.encode_enum<enums::EntityCategory>(11, this->entity_category);
} }
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void ListEntitiesFanResponse::dump_to(std::string &out) const { void ListEntitiesFanResponse::dump_to(std::string &out) const {
@ -1051,6 +1086,10 @@ void ListEntitiesFanResponse::dump_to(std::string &out) const {
out.append(" icon: "); out.append(" icon: ");
out.append("'").append(this->icon).append("'"); out.append("'").append(this->icon).append("'");
out.append("\n"); out.append("\n");
out.append(" entity_category: ");
out.append(proto_enum_to_string<enums::EntityCategory>(this->entity_category));
out.append("\n");
out.append("}"); out.append("}");
} }
#endif #endif
@ -1277,6 +1316,10 @@ bool ListEntitiesLightResponse::decode_varint(uint32_t field_id, ProtoVarInt val
this->disabled_by_default = value.as_bool(); this->disabled_by_default = value.as_bool();
return true; return true;
} }
case 15: {
this->entity_category = value.as_enum<enums::EntityCategory>();
return true;
}
default: default:
return false; return false;
} }
@ -1344,6 +1387,7 @@ void ListEntitiesLightResponse::encode(ProtoWriteBuffer buffer) const {
} }
buffer.encode_bool(13, this->disabled_by_default); buffer.encode_bool(13, this->disabled_by_default);
buffer.encode_string(14, this->icon); buffer.encode_string(14, this->icon);
buffer.encode_enum<enums::EntityCategory>(15, this->entity_category);
} }
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void ListEntitiesLightResponse::dump_to(std::string &out) const { void ListEntitiesLightResponse::dump_to(std::string &out) const {
@ -1411,6 +1455,10 @@ void ListEntitiesLightResponse::dump_to(std::string &out) const {
out.append(" icon: "); out.append(" icon: ");
out.append("'").append(this->icon).append("'"); out.append("'").append(this->icon).append("'");
out.append("\n"); out.append("\n");
out.append(" entity_category: ");
out.append(proto_enum_to_string<enums::EntityCategory>(this->entity_category));
out.append("\n");
out.append("}"); out.append("}");
} }
#endif #endif
@ -1870,6 +1918,10 @@ bool ListEntitiesSensorResponse::decode_varint(uint32_t field_id, ProtoVarInt va
this->disabled_by_default = value.as_bool(); this->disabled_by_default = value.as_bool();
return true; return true;
} }
case 13: {
this->entity_category = value.as_enum<enums::EntityCategory>();
return true;
}
default: default:
return false; return false;
} }
@ -1927,6 +1979,7 @@ void ListEntitiesSensorResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_enum<enums::SensorStateClass>(10, this->state_class); buffer.encode_enum<enums::SensorStateClass>(10, this->state_class);
buffer.encode_enum<enums::SensorLastResetType>(11, this->legacy_last_reset_type); buffer.encode_enum<enums::SensorLastResetType>(11, this->legacy_last_reset_type);
buffer.encode_bool(12, this->disabled_by_default); buffer.encode_bool(12, this->disabled_by_default);
buffer.encode_enum<enums::EntityCategory>(13, this->entity_category);
} }
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void ListEntitiesSensorResponse::dump_to(std::string &out) const { void ListEntitiesSensorResponse::dump_to(std::string &out) const {
@ -1981,6 +2034,10 @@ void ListEntitiesSensorResponse::dump_to(std::string &out) const {
out.append(" disabled_by_default: "); out.append(" disabled_by_default: ");
out.append(YESNO(this->disabled_by_default)); out.append(YESNO(this->disabled_by_default));
out.append("\n"); out.append("\n");
out.append(" entity_category: ");
out.append(proto_enum_to_string<enums::EntityCategory>(this->entity_category));
out.append("\n");
out.append("}"); out.append("}");
} }
#endif #endif
@ -2043,6 +2100,10 @@ bool ListEntitiesSwitchResponse::decode_varint(uint32_t field_id, ProtoVarInt va
this->disabled_by_default = value.as_bool(); this->disabled_by_default = value.as_bool();
return true; return true;
} }
case 8: {
this->entity_category = value.as_enum<enums::EntityCategory>();
return true;
}
default: default:
return false; return false;
} }
@ -2087,6 +2148,7 @@ void ListEntitiesSwitchResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_string(5, this->icon); buffer.encode_string(5, this->icon);
buffer.encode_bool(6, this->assumed_state); buffer.encode_bool(6, this->assumed_state);
buffer.encode_bool(7, this->disabled_by_default); buffer.encode_bool(7, this->disabled_by_default);
buffer.encode_enum<enums::EntityCategory>(8, this->entity_category);
} }
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void ListEntitiesSwitchResponse::dump_to(std::string &out) const { void ListEntitiesSwitchResponse::dump_to(std::string &out) const {
@ -2120,6 +2182,10 @@ void ListEntitiesSwitchResponse::dump_to(std::string &out) const {
out.append(" disabled_by_default: "); out.append(" disabled_by_default: ");
out.append(YESNO(this->disabled_by_default)); out.append(YESNO(this->disabled_by_default));
out.append("\n"); out.append("\n");
out.append(" entity_category: ");
out.append(proto_enum_to_string<enums::EntityCategory>(this->entity_category));
out.append("\n");
out.append("}"); out.append("}");
} }
#endif #endif
@ -2207,6 +2273,10 @@ bool ListEntitiesTextSensorResponse::decode_varint(uint32_t field_id, ProtoVarIn
this->disabled_by_default = value.as_bool(); this->disabled_by_default = value.as_bool();
return true; return true;
} }
case 7: {
this->entity_category = value.as_enum<enums::EntityCategory>();
return true;
}
default: default:
return false; return false;
} }
@ -2250,6 +2320,7 @@ void ListEntitiesTextSensorResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_string(4, this->unique_id); buffer.encode_string(4, this->unique_id);
buffer.encode_string(5, this->icon); buffer.encode_string(5, this->icon);
buffer.encode_bool(6, this->disabled_by_default); buffer.encode_bool(6, this->disabled_by_default);
buffer.encode_enum<enums::EntityCategory>(7, this->entity_category);
} }
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void ListEntitiesTextSensorResponse::dump_to(std::string &out) const { void ListEntitiesTextSensorResponse::dump_to(std::string &out) const {
@ -2279,6 +2350,10 @@ void ListEntitiesTextSensorResponse::dump_to(std::string &out) const {
out.append(" disabled_by_default: "); out.append(" disabled_by_default: ");
out.append(YESNO(this->disabled_by_default)); out.append(YESNO(this->disabled_by_default));
out.append("\n"); out.append("\n");
out.append(" entity_category: ");
out.append(proto_enum_to_string<enums::EntityCategory>(this->entity_category));
out.append("\n");
out.append("}"); out.append("}");
} }
#endif #endif
@ -2902,6 +2977,10 @@ bool ListEntitiesCameraResponse::decode_varint(uint32_t field_id, ProtoVarInt va
this->disabled_by_default = value.as_bool(); this->disabled_by_default = value.as_bool();
return true; return true;
} }
case 7: {
this->entity_category = value.as_enum<enums::EntityCategory>();
return true;
}
default: default:
return false; return false;
} }
@ -2945,6 +3024,7 @@ void ListEntitiesCameraResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_string(4, this->unique_id); buffer.encode_string(4, this->unique_id);
buffer.encode_bool(5, this->disabled_by_default); buffer.encode_bool(5, this->disabled_by_default);
buffer.encode_string(6, this->icon); buffer.encode_string(6, this->icon);
buffer.encode_enum<enums::EntityCategory>(7, this->entity_category);
} }
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void ListEntitiesCameraResponse::dump_to(std::string &out) const { void ListEntitiesCameraResponse::dump_to(std::string &out) const {
@ -2974,6 +3054,10 @@ void ListEntitiesCameraResponse::dump_to(std::string &out) const {
out.append(" icon: "); out.append(" icon: ");
out.append("'").append(this->icon).append("'"); out.append("'").append(this->icon).append("'");
out.append("\n"); out.append("\n");
out.append(" entity_category: ");
out.append(proto_enum_to_string<enums::EntityCategory>(this->entity_category));
out.append("\n");
out.append("}"); out.append("}");
} }
#endif #endif
@ -3101,6 +3185,10 @@ bool ListEntitiesClimateResponse::decode_varint(uint32_t field_id, ProtoVarInt v
this->disabled_by_default = value.as_bool(); this->disabled_by_default = value.as_bool();
return true; return true;
} }
case 20: {
this->entity_category = value.as_enum<enums::EntityCategory>();
return true;
}
default: default:
return false; return false;
} }
@ -3189,6 +3277,7 @@ void ListEntitiesClimateResponse::encode(ProtoWriteBuffer buffer) const {
} }
buffer.encode_bool(18, this->disabled_by_default); buffer.encode_bool(18, this->disabled_by_default);
buffer.encode_string(19, this->icon); buffer.encode_string(19, this->icon);
buffer.encode_enum<enums::EntityCategory>(20, this->entity_category);
} }
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void ListEntitiesClimateResponse::dump_to(std::string &out) const { void ListEntitiesClimateResponse::dump_to(std::string &out) const {
@ -3285,6 +3374,10 @@ void ListEntitiesClimateResponse::dump_to(std::string &out) const {
out.append(" icon: "); out.append(" icon: ");
out.append("'").append(this->icon).append("'"); out.append("'").append(this->icon).append("'");
out.append("\n"); out.append("\n");
out.append(" entity_category: ");
out.append(proto_enum_to_string<enums::EntityCategory>(this->entity_category));
out.append("\n");
out.append("}"); out.append("}");
} }
#endif #endif
@ -3661,6 +3754,10 @@ bool ListEntitiesNumberResponse::decode_varint(uint32_t field_id, ProtoVarInt va
this->disabled_by_default = value.as_bool(); this->disabled_by_default = value.as_bool();
return true; return true;
} }
case 10: {
this->entity_category = value.as_enum<enums::EntityCategory>();
return true;
}
default: default:
return false; return false;
} }
@ -3719,6 +3816,7 @@ void ListEntitiesNumberResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_float(7, this->max_value); buffer.encode_float(7, this->max_value);
buffer.encode_float(8, this->step); buffer.encode_float(8, this->step);
buffer.encode_bool(9, this->disabled_by_default); buffer.encode_bool(9, this->disabled_by_default);
buffer.encode_enum<enums::EntityCategory>(10, this->entity_category);
} }
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void ListEntitiesNumberResponse::dump_to(std::string &out) const { void ListEntitiesNumberResponse::dump_to(std::string &out) const {
@ -3763,6 +3861,10 @@ void ListEntitiesNumberResponse::dump_to(std::string &out) const {
out.append(" disabled_by_default: "); out.append(" disabled_by_default: ");
out.append(YESNO(this->disabled_by_default)); out.append(YESNO(this->disabled_by_default));
out.append("\n"); out.append("\n");
out.append(" entity_category: ");
out.append(proto_enum_to_string<enums::EntityCategory>(this->entity_category));
out.append("\n");
out.append("}"); out.append("}");
} }
#endif #endif
@ -3855,6 +3957,10 @@ bool ListEntitiesSelectResponse::decode_varint(uint32_t field_id, ProtoVarInt va
this->disabled_by_default = value.as_bool(); this->disabled_by_default = value.as_bool();
return true; return true;
} }
case 8: {
this->entity_category = value.as_enum<enums::EntityCategory>();
return true;
}
default: default:
return false; return false;
} }
@ -3905,6 +4011,7 @@ void ListEntitiesSelectResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_string(6, it, true); buffer.encode_string(6, it, true);
} }
buffer.encode_bool(7, this->disabled_by_default); buffer.encode_bool(7, this->disabled_by_default);
buffer.encode_enum<enums::EntityCategory>(8, this->entity_category);
} }
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void ListEntitiesSelectResponse::dump_to(std::string &out) const { void ListEntitiesSelectResponse::dump_to(std::string &out) const {
@ -3940,6 +4047,10 @@ void ListEntitiesSelectResponse::dump_to(std::string &out) const {
out.append(" disabled_by_default: "); out.append(" disabled_by_default: ");
out.append(YESNO(this->disabled_by_default)); out.append(YESNO(this->disabled_by_default));
out.append("\n"); out.append("\n");
out.append(" entity_category: ");
out.append(proto_enum_to_string<enums::EntityCategory>(this->entity_category));
out.append("\n");
out.append("}"); out.append("}");
} }
#endif #endif

View file

@ -9,6 +9,11 @@ namespace api {
namespace enums { namespace enums {
enum EntityCategory : uint32_t {
ENTITY_CATEGORY_NONE = 0,
ENTITY_CATEGORY_CONFIG = 1,
ENTITY_CATEGORY_DIAGNOSTIC = 2,
};
enum LegacyCoverState : uint32_t { enum LegacyCoverState : uint32_t {
LEGACY_COVER_STATE_OPEN = 0, LEGACY_COVER_STATE_OPEN = 0,
LEGACY_COVER_STATE_CLOSED = 1, LEGACY_COVER_STATE_CLOSED = 1,
@ -271,6 +276,7 @@ class ListEntitiesBinarySensorResponse : public ProtoMessage {
bool is_status_binary_sensor{false}; bool is_status_binary_sensor{false};
bool disabled_by_default{false}; bool disabled_by_default{false};
std::string icon{}; std::string icon{};
enums::EntityCategory entity_category{};
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;
@ -307,6 +313,7 @@ class ListEntitiesCoverResponse : public ProtoMessage {
std::string device_class{}; std::string device_class{};
bool disabled_by_default{false}; bool disabled_by_default{false};
std::string icon{}; std::string icon{};
enums::EntityCategory entity_category{};
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;
@ -364,6 +371,7 @@ class ListEntitiesFanResponse : public ProtoMessage {
int32_t supported_speed_count{0}; int32_t supported_speed_count{0};
bool disabled_by_default{false}; bool disabled_by_default{false};
std::string icon{}; std::string icon{};
enums::EntityCategory entity_category{};
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;
@ -429,6 +437,7 @@ class ListEntitiesLightResponse : public ProtoMessage {
std::vector<std::string> effects{}; std::vector<std::string> effects{};
bool disabled_by_default{false}; bool disabled_by_default{false};
std::string icon{}; std::string icon{};
enums::EntityCategory entity_category{};
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;
@ -517,6 +526,7 @@ class ListEntitiesSensorResponse : public ProtoMessage {
enums::SensorStateClass state_class{}; enums::SensorStateClass state_class{};
enums::SensorLastResetType legacy_last_reset_type{}; enums::SensorLastResetType legacy_last_reset_type{};
bool disabled_by_default{false}; bool disabled_by_default{false};
enums::EntityCategory entity_category{};
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;
@ -550,6 +560,7 @@ class ListEntitiesSwitchResponse : public ProtoMessage {
std::string icon{}; std::string icon{};
bool assumed_state{false}; bool assumed_state{false};
bool disabled_by_default{false}; bool disabled_by_default{false};
enums::EntityCategory entity_category{};
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;
@ -594,6 +605,7 @@ class ListEntitiesTextSensorResponse : public ProtoMessage {
std::string unique_id{}; std::string unique_id{};
std::string icon{}; std::string icon{};
bool disabled_by_default{false}; bool disabled_by_default{false};
enums::EntityCategory entity_category{};
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;
@ -805,6 +817,7 @@ class ListEntitiesCameraResponse : public ProtoMessage {
std::string unique_id{}; std::string unique_id{};
bool disabled_by_default{false}; bool disabled_by_default{false};
std::string icon{}; std::string icon{};
enums::EntityCategory entity_category{};
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;
@ -863,6 +876,7 @@ class ListEntitiesClimateResponse : public ProtoMessage {
std::vector<std::string> supported_custom_presets{}; std::vector<std::string> supported_custom_presets{};
bool disabled_by_default{false}; bool disabled_by_default{false};
std::string icon{}; std::string icon{};
enums::EntityCategory entity_category{};
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;
@ -942,6 +956,7 @@ class ListEntitiesNumberResponse : public ProtoMessage {
float max_value{0.0f}; float max_value{0.0f};
float step{0.0f}; float step{0.0f};
bool disabled_by_default{false}; bool disabled_by_default{false};
enums::EntityCategory entity_category{};
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;
@ -987,6 +1002,7 @@ class ListEntitiesSelectResponse : public ProtoMessage {
std::string icon{}; std::string icon{};
std::vector<std::string> options{}; std::vector<std::string> options{};
bool disabled_by_default{false}; bool disabled_by_default{false};
enums::EntityCategory entity_category{};
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;

View file

@ -12,6 +12,7 @@ from esphome.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
@ -49,12 +50,14 @@ CONFIG_SCHEMA = (
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY, device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_BATTERY_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_BATTERY_VOLTAGE): sensor.sensor_schema(
unit_of_measurement=UNIT_VOLT, unit_of_measurement=UNIT_VOLT,
accuracy_decimals=3, accuracy_decimals=3,
device_class=DEVICE_CLASS_VOLTAGE, device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
} }
) )

View file

@ -17,6 +17,7 @@ from esphome.const import (
DEVICE_CLASS_POWER_FACTOR, DEVICE_CLASS_POWER_FACTOR,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ENTITY_CATEGORY_DIAGNOSTIC,
ICON_LIGHTBULB, ICON_LIGHTBULB,
ICON_CURRENT_AC, ICON_CURRENT_AC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
@ -125,6 +126,7 @@ CONFIG_SCHEMA = (
accuracy_decimals=1, accuracy_decimals=1,
device_class=DEVICE_CLASS_TEMPERATURE, device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Required(CONF_LINE_FREQUENCY): cv.enum(LINE_FREQS, upper=True), cv.Required(CONF_LINE_FREQUENCY): cv.enum(LINE_FREQS, upper=True),
cv.Optional(CONF_CURRENT_PHASES, default="3"): cv.enum( cv.Optional(CONF_CURRENT_PHASES, default="3"): cv.enum(

View file

@ -13,6 +13,7 @@ from esphome.const import (
DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_LUX, UNIT_LUX,
@ -51,6 +52,7 @@ CONFIG_SCHEMA = (
accuracy_decimals=3, accuracy_decimals=3,
device_class=DEVICE_CLASS_VOLTAGE, device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_MOISTURE): sensor.sensor_schema( cv.Optional(CONF_MOISTURE): sensor.sensor_schema(
unit_of_measurement=UNIT_PERCENT, unit_of_measurement=UNIT_PERCENT,

View file

@ -313,6 +313,7 @@ def validate_multi_click_timing(value):
device_class = cv.one_of(*DEVICE_CLASSES, lower=True, space="_") device_class = cv.one_of(*DEVICE_CLASSES, lower=True, space="_")
BINARY_SENSOR_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMPONENT_SCHEMA).extend( BINARY_SENSOR_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMPONENT_SCHEMA).extend(
{ {
cv.GenerateID(): cv.declare_id(BinarySensor), cv.GenerateID(): cv.declare_id(BinarySensor),

View file

@ -8,6 +8,7 @@ from esphome.const import (
CONF_LAST_FINGER_ID, CONF_LAST_FINGER_ID,
CONF_SECURITY_LEVEL, CONF_SECURITY_LEVEL,
CONF_STATUS, CONF_STATUS,
ENTITY_CATEGORY_DIAGNOSTIC,
ICON_ACCOUNT, ICON_ACCOUNT,
ICON_ACCOUNT_CHECK, ICON_ACCOUNT_CHECK,
ICON_DATABASE, ICON_DATABASE,
@ -26,30 +27,36 @@ CONFIG_SCHEMA = cv.Schema(
icon=ICON_FINGERPRINT, icon=ICON_FINGERPRINT,
accuracy_decimals=0, accuracy_decimals=0,
state_class=STATE_CLASS_NONE, state_class=STATE_CLASS_NONE,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_STATUS): sensor.sensor_schema( cv.Optional(CONF_STATUS): sensor.sensor_schema(
accuracy_decimals=0, accuracy_decimals=0,
state_class=STATE_CLASS_NONE, state_class=STATE_CLASS_NONE,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_CAPACITY): sensor.sensor_schema( cv.Optional(CONF_CAPACITY): sensor.sensor_schema(
icon=ICON_DATABASE, icon=ICON_DATABASE,
accuracy_decimals=0, accuracy_decimals=0,
state_class=STATE_CLASS_NONE, state_class=STATE_CLASS_NONE,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_SECURITY_LEVEL): sensor.sensor_schema( cv.Optional(CONF_SECURITY_LEVEL): sensor.sensor_schema(
icon=ICON_SECURITY, icon=ICON_SECURITY,
accuracy_decimals=0, accuracy_decimals=0,
state_class=STATE_CLASS_NONE, state_class=STATE_CLASS_NONE,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_LAST_FINGER_ID): sensor.sensor_schema( cv.Optional(CONF_LAST_FINGER_ID): sensor.sensor_schema(
icon=ICON_ACCOUNT, icon=ICON_ACCOUNT,
accuracy_decimals=0, accuracy_decimals=0,
state_class=STATE_CLASS_NONE, state_class=STATE_CLASS_NONE,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_LAST_CONFIDENCE): sensor.sensor_schema( cv.Optional(CONF_LAST_CONFIDENCE): sensor.sensor_schema(
icon=ICON_ACCOUNT_CHECK, icon=ICON_ACCOUNT_CHECK,
accuracy_decimals=0, accuracy_decimals=0,
state_class=STATE_CLASS_NONE, state_class=STATE_CLASS_NONE,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
} }
) )

View file

@ -9,6 +9,7 @@ from esphome.const import (
DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
@ -53,6 +54,7 @@ CONFIG_SCHEMA = (
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY, device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
} }
) )

View file

@ -41,7 +41,6 @@ NumberInRangeCondition = number_ns.class_(
icon = cv.icon icon = cv.icon
NUMBER_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMPONENT_SCHEMA).extend( NUMBER_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMPONENT_SCHEMA).extend(
{ {
cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTNumberComponent), cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTNumberComponent),

View file

@ -12,6 +12,7 @@ from esphome.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
@ -49,12 +50,14 @@ CONFIG_SCHEMA = (
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY, device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_BATTERY_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_BATTERY_VOLTAGE): sensor.sensor_schema(
unit_of_measurement=UNIT_VOLT, unit_of_measurement=UNIT_VOLT,
accuracy_decimals=3, accuracy_decimals=3,
device_class=DEVICE_CLASS_VOLTAGE, device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
} }
) )

View file

@ -1,7 +1,14 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import switch from esphome.components import switch
from esphome.const import CONF_ID, CONF_INVERTED, CONF_ICON, ICON_RESTART from esphome.const import (
CONF_ENTITY_CATEGORY,
CONF_ID,
CONF_INVERTED,
CONF_ICON,
ENTITY_CATEGORY_CONFIG,
ICON_RESTART,
)
restart_ns = cg.esphome_ns.namespace("restart") restart_ns = cg.esphome_ns.namespace("restart")
RestartSwitch = restart_ns.class_("RestartSwitch", switch.Switch, cg.Component) RestartSwitch = restart_ns.class_("RestartSwitch", switch.Switch, cg.Component)
@ -13,6 +20,9 @@ CONFIG_SCHEMA = switch.SWITCH_SCHEMA.extend(
"Restart switches do not support inverted mode!" "Restart switches do not support inverted mode!"
), ),
cv.Optional(CONF_ICON, default=ICON_RESTART): switch.icon, cv.Optional(CONF_ICON, default=ICON_RESTART): switch.icon,
cv.Optional(
CONF_ENTITY_CATEGORY, default=ENTITY_CATEGORY_CONFIG
): cv.entity_category,
} }
).extend(cv.COMPONENT_SCHEMA) ).extend(cv.COMPONENT_SCHEMA)

View file

@ -19,6 +19,7 @@ from esphome.const import (
DEVICE_CLASS_SIGNAL_STRENGTH, DEVICE_CLASS_SIGNAL_STRENGTH,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
STATE_CLASS_NONE, STATE_CLASS_NONE,
UNIT_CELSIUS, UNIT_CELSIUS,
@ -95,22 +96,26 @@ CONFIG_SCHEMA = (
accuracy_decimals=3, accuracy_decimals=3,
device_class=DEVICE_CLASS_VOLTAGE, device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_TX_POWER): sensor.sensor_schema( cv.Optional(CONF_TX_POWER): sensor.sensor_schema(
unit_of_measurement=UNIT_DECIBEL_MILLIWATT, unit_of_measurement=UNIT_DECIBEL_MILLIWATT,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_SIGNAL_STRENGTH, device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_MOVEMENT_COUNTER): sensor.sensor_schema( cv.Optional(CONF_MOVEMENT_COUNTER): sensor.sensor_schema(
icon=ICON_GAUGE, icon=ICON_GAUGE,
accuracy_decimals=0, accuracy_decimals=0,
state_class=STATE_CLASS_NONE, state_class=STATE_CLASS_NONE,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_MEASUREMENT_SEQUENCE_NUMBER): sensor.sensor_schema( cv.Optional(CONF_MEASUREMENT_SEQUENCE_NUMBER): sensor.sensor_schema(
icon=ICON_GAUGE, icon=ICON_GAUGE,
accuracy_decimals=0, accuracy_decimals=0,
state_class=STATE_CLASS_NONE, state_class=STATE_CLASS_NONE,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
} }
) )

View file

@ -3,10 +3,12 @@ import esphome.config_validation as cv
from esphome.components import switch from esphome.components import switch
from esphome.components.ota import OTAComponent from esphome.components.ota import OTAComponent
from esphome.const import ( from esphome.const import (
CONF_ENTITY_CATEGORY,
CONF_ID, CONF_ID,
CONF_INVERTED, CONF_INVERTED,
CONF_ICON, CONF_ICON,
CONF_OTA, CONF_OTA,
ENTITY_CATEGORY_CONFIG,
ICON_RESTART_ALERT, ICON_RESTART_ALERT,
) )
from .. import safe_mode_ns from .. import safe_mode_ns
@ -23,6 +25,9 @@ CONFIG_SCHEMA = switch.SWITCH_SCHEMA.extend(
"Safe Mode Restart switches do not support inverted mode!" "Safe Mode Restart switches do not support inverted mode!"
), ),
cv.Optional(CONF_ICON, default=ICON_RESTART_ALERT): switch.icon, cv.Optional(CONF_ICON, default=ICON_RESTART_ALERT): switch.icon,
cv.Optional(
CONF_ENTITY_CATEGORY, default=ENTITY_CATEGORY_CONFIG
): cv.entity_category,
} }
).extend(cv.COMPONENT_SCHEMA) ).extend(cv.COMPONENT_SCHEMA)

View file

@ -30,7 +30,6 @@ SelectSetAction = select_ns.class_("SelectSetAction", automation.Action)
icon = cv.icon icon = cv.icon
SELECT_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMPONENT_SCHEMA).extend( SELECT_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMPONENT_SCHEMA).extend(
{ {
cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTSelectComponent), cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTSelectComponent),

View file

@ -10,6 +10,7 @@ from esphome.const import (
CONF_ACCURACY_DECIMALS, CONF_ACCURACY_DECIMALS,
CONF_ALPHA, CONF_ALPHA,
CONF_BELOW, CONF_BELOW,
CONF_ENTITY_CATEGORY,
CONF_EXPIRE_AFTER, CONF_EXPIRE_AFTER,
CONF_FILTERS, CONF_FILTERS,
CONF_FROM, CONF_FROM,
@ -133,7 +134,6 @@ def validate_datapoint(value):
# Base # Base
sensor_ns = cg.esphome_ns.namespace("sensor")
Sensor = sensor_ns.class_("Sensor", cg.EntityBase) Sensor = sensor_ns.class_("Sensor", cg.EntityBase)
SensorPtr = Sensor.operator("ptr") SensorPtr = Sensor.operator("ptr")
@ -226,6 +226,7 @@ def sensor_schema(
accuracy_decimals: int = _UNDEF, accuracy_decimals: int = _UNDEF,
device_class: str = _UNDEF, device_class: str = _UNDEF,
state_class: str = _UNDEF, state_class: str = _UNDEF,
entity_category: str = _UNDEF,
) -> cv.Schema: ) -> cv.Schema:
schema = SENSOR_SCHEMA schema = SENSOR_SCHEMA
if unit_of_measurement is not _UNDEF: if unit_of_measurement is not _UNDEF:
@ -258,6 +259,14 @@ def sensor_schema(
schema = schema.extend( schema = schema.extend(
{cv.Optional(CONF_STATE_CLASS, default=state_class): validate_state_class} {cv.Optional(CONF_STATE_CLASS, default=state_class): validate_state_class}
) )
if entity_category is not _UNDEF:
schema = schema.extend(
{
cv.Optional(
CONF_ENTITY_CATEGORY, default=entity_category
): cv.entity_category
}
)
return schema return schema

View file

@ -1,7 +1,14 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import switch from esphome.components import switch
from esphome.const import CONF_ID, CONF_INVERTED, CONF_ICON, ICON_POWER from esphome.const import (
CONF_ENTITY_CATEGORY,
CONF_ID,
CONF_INVERTED,
CONF_ICON,
ENTITY_CATEGORY_CONFIG,
ICON_POWER,
)
shutdown_ns = cg.esphome_ns.namespace("shutdown") shutdown_ns = cg.esphome_ns.namespace("shutdown")
ShutdownSwitch = shutdown_ns.class_("ShutdownSwitch", switch.Switch, cg.Component) ShutdownSwitch = shutdown_ns.class_("ShutdownSwitch", switch.Switch, cg.Component)
@ -13,6 +20,9 @@ CONFIG_SCHEMA = switch.SWITCH_SCHEMA.extend(
"Shutdown switches do not support inverted mode!" "Shutdown switches do not support inverted mode!"
), ),
cv.Optional(CONF_ICON, default=ICON_POWER): switch.icon, cv.Optional(CONF_ICON, default=ICON_POWER): switch.icon,
cv.Optional(
CONF_ENTITY_CATEGORY, default=ENTITY_CATEGORY_CONFIG
): cv.entity_category,
} }
).extend(cv.COMPONENT_SCHEMA) ).extend(cv.COMPONENT_SCHEMA)

View file

@ -1,7 +1,13 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import binary_sensor from esphome.components import binary_sensor
from esphome.const import CONF_ID, CONF_DEVICE_CLASS, DEVICE_CLASS_CONNECTIVITY from esphome.const import (
CONF_ENTITY_CATEGORY,
CONF_ID,
CONF_DEVICE_CLASS,
DEVICE_CLASS_CONNECTIVITY,
ENTITY_CATEGORY_DIAGNOSTIC,
)
status_ns = cg.esphome_ns.namespace("status") status_ns = cg.esphome_ns.namespace("status")
StatusBinarySensor = status_ns.class_( StatusBinarySensor = status_ns.class_(
@ -14,6 +20,9 @@ CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend(
cv.Optional( cv.Optional(
CONF_DEVICE_CLASS, default=DEVICE_CLASS_CONNECTIVITY CONF_DEVICE_CLASS, default=DEVICE_CLASS_CONNECTIVITY
): binary_sensor.device_class, ): binary_sensor.device_class,
cv.Optional(
CONF_ENTITY_CATEGORY, default=ENTITY_CATEGORY_DIAGNOSTIC
): cv.entity_category,
} }
).extend(cv.COMPONENT_SCHEMA) ).extend(cv.COMPONENT_SCHEMA)

View file

@ -36,6 +36,7 @@ SwitchTurnOffTrigger = switch_ns.class_(
icon = cv.icon icon = cv.icon
SWITCH_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMMAND_COMPONENT_SCHEMA).extend( SWITCH_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMMAND_COMPONENT_SCHEMA).extend(
{ {
cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTSwitchComponent), cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTSwitchComponent),

View file

@ -108,6 +108,7 @@ async def substitute_filter_to_code(config, filter_id):
icon = cv.icon icon = cv.icon
TEXT_SENSOR_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMPONENT_SCHEMA).extend( TEXT_SENSOR_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMPONENT_SCHEMA).extend(
{ {
cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTTextSensor), cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTTextSensor),

View file

@ -3,6 +3,7 @@ import esphome.config_validation as cv
from esphome.components import sensor from esphome.components import sensor
from esphome.const import ( from esphome.const import (
CONF_ID, CONF_ID,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_TOTAL_INCREASING, STATE_CLASS_TOTAL_INCREASING,
UNIT_SECOND, UNIT_SECOND,
ICON_TIMER, ICON_TIMER,
@ -17,6 +18,7 @@ CONFIG_SCHEMA = (
icon=ICON_TIMER, icon=ICON_TIMER,
accuracy_decimals=0, accuracy_decimals=0,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=STATE_CLASS_TOTAL_INCREASING,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
) )
.extend( .extend(
{ {

View file

@ -1,7 +1,14 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import text_sensor from esphome.components import text_sensor
from esphome.const import CONF_ID, CONF_ICON, ICON_NEW_BOX, CONF_HIDE_TIMESTAMP from esphome.const import (
CONF_ENTITY_CATEGORY,
CONF_ID,
CONF_ICON,
ENTITY_CATEGORY_DIAGNOSTIC,
ICON_NEW_BOX,
CONF_HIDE_TIMESTAMP,
)
version_ns = cg.esphome_ns.namespace("version") version_ns = cg.esphome_ns.namespace("version")
VersionTextSensor = version_ns.class_( VersionTextSensor = version_ns.class_(
@ -13,6 +20,9 @@ CONFIG_SCHEMA = text_sensor.TEXT_SENSOR_SCHEMA.extend(
cv.GenerateID(): cv.declare_id(VersionTextSensor), cv.GenerateID(): cv.declare_id(VersionTextSensor),
cv.Optional(CONF_ICON, default=ICON_NEW_BOX): text_sensor.icon, cv.Optional(CONF_ICON, default=ICON_NEW_BOX): text_sensor.icon,
cv.Optional(CONF_HIDE_TIMESTAMP, default=False): cv.boolean, cv.Optional(CONF_HIDE_TIMESTAMP, default=False): cv.boolean,
cv.Optional(
CONF_ENTITY_CATEGORY, default=ENTITY_CATEGORY_DIAGNOSTIC
): cv.entity_category,
} }
).extend(cv.COMPONENT_SCHEMA) ).extend(cv.COMPONENT_SCHEMA)

View file

@ -3,11 +3,13 @@ import esphome.config_validation as cv
from esphome.components import text_sensor from esphome.components import text_sensor
from esphome.const import ( from esphome.const import (
CONF_BSSID, CONF_BSSID,
CONF_ENTITY_CATEGORY,
CONF_ID, CONF_ID,
CONF_IP_ADDRESS, CONF_IP_ADDRESS,
CONF_SCAN_RESULTS, CONF_SCAN_RESULTS,
CONF_SSID, CONF_SSID,
CONF_MAC_ADDRESS, CONF_MAC_ADDRESS,
ENTITY_CATEGORY_DIAGNOSTIC,
) )
DEPENDENCIES = ["wifi"] DEPENDENCIES = ["wifi"]
@ -32,26 +34,41 @@ CONFIG_SCHEMA = cv.Schema(
cv.Optional(CONF_IP_ADDRESS): text_sensor.TEXT_SENSOR_SCHEMA.extend( cv.Optional(CONF_IP_ADDRESS): text_sensor.TEXT_SENSOR_SCHEMA.extend(
{ {
cv.GenerateID(): cv.declare_id(IPAddressWiFiInfo), cv.GenerateID(): cv.declare_id(IPAddressWiFiInfo),
cv.Optional(
CONF_ENTITY_CATEGORY, default=ENTITY_CATEGORY_DIAGNOSTIC
): cv.entity_category,
} }
), ),
cv.Optional(CONF_SCAN_RESULTS): text_sensor.TEXT_SENSOR_SCHEMA.extend( cv.Optional(CONF_SCAN_RESULTS): text_sensor.TEXT_SENSOR_SCHEMA.extend(
{ {
cv.GenerateID(): cv.declare_id(ScanResultsWiFiInfo), cv.GenerateID(): cv.declare_id(ScanResultsWiFiInfo),
cv.Optional(
CONF_ENTITY_CATEGORY, default=ENTITY_CATEGORY_DIAGNOSTIC
): cv.entity_category,
} }
).extend(cv.polling_component_schema("60s")), ).extend(cv.polling_component_schema("60s")),
cv.Optional(CONF_SSID): text_sensor.TEXT_SENSOR_SCHEMA.extend( cv.Optional(CONF_SSID): text_sensor.TEXT_SENSOR_SCHEMA.extend(
{ {
cv.GenerateID(): cv.declare_id(SSIDWiFiInfo), cv.GenerateID(): cv.declare_id(SSIDWiFiInfo),
cv.Optional(
CONF_ENTITY_CATEGORY, default=ENTITY_CATEGORY_DIAGNOSTIC
): cv.entity_category,
} }
), ),
cv.Optional(CONF_BSSID): text_sensor.TEXT_SENSOR_SCHEMA.extend( cv.Optional(CONF_BSSID): text_sensor.TEXT_SENSOR_SCHEMA.extend(
{ {
cv.GenerateID(): cv.declare_id(BSSIDWiFiInfo), cv.GenerateID(): cv.declare_id(BSSIDWiFiInfo),
cv.Optional(
CONF_ENTITY_CATEGORY, default=ENTITY_CATEGORY_DIAGNOSTIC
): cv.entity_category,
} }
), ),
cv.Optional(CONF_MAC_ADDRESS): text_sensor.TEXT_SENSOR_SCHEMA.extend( cv.Optional(CONF_MAC_ADDRESS): text_sensor.TEXT_SENSOR_SCHEMA.extend(
{ {
cv.GenerateID(): cv.declare_id(MacAddressWifiInfo), cv.GenerateID(): cv.declare_id(MacAddressWifiInfo),
cv.Optional(
CONF_ENTITY_CATEGORY, default=ENTITY_CATEGORY_DIAGNOSTIC
): cv.entity_category,
} }
), ),
} }

View file

@ -4,6 +4,7 @@ from esphome.components import sensor
from esphome.const import ( from esphome.const import (
CONF_ID, CONF_ID,
DEVICE_CLASS_SIGNAL_STRENGTH, DEVICE_CLASS_SIGNAL_STRENGTH,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_DECIBEL_MILLIWATT, UNIT_DECIBEL_MILLIWATT,
) )
@ -20,6 +21,7 @@ CONFIG_SCHEMA = (
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_SIGNAL_STRENGTH, device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
) )
.extend( .extend(
{ {

View file

@ -10,6 +10,7 @@ from esphome.const import (
DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
@ -47,6 +48,7 @@ CONFIG_SCHEMA = (
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY, device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
} }
) )

View file

@ -9,6 +9,7 @@ from esphome.const import (
DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
@ -47,6 +48,7 @@ CONFIG_SCHEMA = (
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY, device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
} }
) )

View file

@ -11,6 +11,7 @@ from esphome.const import (
DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
@ -47,6 +48,7 @@ CONFIG_SCHEMA = (
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY, device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
} }
) )

View file

@ -10,6 +10,8 @@ from esphome.const import (
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY,
DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_MOTION,
ENTITY_CATEGORY_DIAGNOSTIC,
ICON_EMPTY, ICON_EMPTY,
UNIT_PERCENT, UNIT_PERCENT,
CONF_IDLE_TIME, CONF_IDLE_TIME,
@ -37,13 +39,21 @@ CONFIG_SCHEMA = cv.All(
cv.Required(CONF_BINDKEY): cv.bind_key, cv.Required(CONF_BINDKEY): cv.bind_key,
cv.Required(CONF_MAC_ADDRESS): cv.mac_address, cv.Required(CONF_MAC_ADDRESS): cv.mac_address,
cv.Optional( cv.Optional(
CONF_DEVICE_CLASS, default="motion" CONF_DEVICE_CLASS,
default=DEVICE_CLASS_MOTION,
): binary_sensor.device_class, ): binary_sensor.device_class,
cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema( cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 0, DEVICE_CLASS_BATTERY unit_of_measurement=UNIT_PERCENT,
accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_IDLE_TIME): sensor.sensor_schema( cv.Optional(CONF_IDLE_TIME): sensor.sensor_schema(
UNIT_MINUTE, ICON_TIMELAPSE, 0, DEVICE_CLASS_EMPTY unit_of_measurement=UNIT_MINUTE,
icon=ICON_TIMELAPSE,
accuracy_decimals=0,
device_class=DEVICE_CLASS_EMPTY,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_ILLUMINANCE): sensor.sensor_schema( cv.Optional(CONF_ILLUMINANCE): sensor.sensor_schema(
UNIT_LUX, ICON_EMPTY, 0, DEVICE_CLASS_ILLUMINANCE UNIT_LUX, ICON_EMPTY, 0, DEVICE_CLASS_ILLUMINANCE

View file

@ -6,6 +6,7 @@ from esphome.const import (
CONF_TEMPERATURE, CONF_TEMPERATURE,
DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ENTITY_CATEGORY_DIAGNOSTIC,
ICON_WATER_PERCENT, ICON_WATER_PERCENT,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
@ -63,6 +64,7 @@ CONFIG_SCHEMA = (
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY, device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
} }
) )

View file

@ -9,6 +9,7 @@ from esphome.const import (
DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
@ -54,6 +55,7 @@ CONFIG_SCHEMA = (
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY, device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
} }
) )

View file

@ -7,6 +7,7 @@ from esphome.const import (
CONF_MAC_ADDRESS, CONF_MAC_ADDRESS,
CONF_TEMPERATURE, CONF_TEMPERATURE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
@ -45,6 +46,7 @@ CONFIG_SCHEMA = (
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY, device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
} }
) )

View file

@ -6,6 +6,7 @@ from esphome.const import (
CONF_HUMIDITY, CONF_HUMIDITY,
CONF_MAC_ADDRESS, CONF_MAC_ADDRESS,
CONF_TEMPERATURE, CONF_TEMPERATURE,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
@ -49,6 +50,7 @@ CONFIG_SCHEMA = (
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY, device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
} }
) )

View file

@ -6,6 +6,7 @@ from esphome.const import (
CONF_HUMIDITY, CONF_HUMIDITY,
CONF_MAC_ADDRESS, CONF_MAC_ADDRESS,
CONF_TEMPERATURE, CONF_TEMPERATURE,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
@ -45,6 +46,7 @@ CONFIG_SCHEMA = (
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY, device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
} }
) )

View file

@ -6,6 +6,7 @@ from esphome.const import (
CONF_HUMIDITY, CONF_HUMIDITY,
CONF_MAC_ADDRESS, CONF_MAC_ADDRESS,
CONF_TEMPERATURE, CONF_TEMPERATURE,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
@ -48,6 +49,7 @@ CONFIG_SCHEMA = (
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY, device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
} }
) )

View file

@ -10,6 +10,7 @@ from esphome.const import (
CONF_BATTERY_LEVEL, CONF_BATTERY_LEVEL,
DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY,
DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_ILLUMINANCE,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
STATE_CLASS_NONE, STATE_CLASS_NONE,
UNIT_PERCENT, UNIT_PERCENT,
@ -51,6 +52,7 @@ CONFIG_SCHEMA = cv.All(
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY, device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
cv.Optional(CONF_ILLUMINANCE): sensor.sensor_schema( cv.Optional(CONF_ILLUMINANCE): sensor.sensor_schema(
unit_of_measurement=UNIT_LUX, unit_of_measurement=UNIT_LUX,

View file

@ -6,6 +6,7 @@ from esphome.const import (
CONF_MAC_ADDRESS, CONF_MAC_ADDRESS,
CONF_TABLET, CONF_TABLET,
DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_PERCENT, UNIT_PERCENT,
ICON_BUG, ICON_BUG,
@ -40,6 +41,7 @@ CONFIG_SCHEMA = cv.All(
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY, device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
} }
) )

View file

@ -12,12 +12,14 @@ from string import ascii_letters, digits
import voluptuous as vol import voluptuous as vol
from esphome import core from esphome import core
import esphome.codegen as cg
from esphome.const import ( from esphome.const import (
ALLOWED_NAME_CHARS, ALLOWED_NAME_CHARS,
CONF_AVAILABILITY, CONF_AVAILABILITY,
CONF_COMMAND_TOPIC, CONF_COMMAND_TOPIC,
CONF_DISABLED_BY_DEFAULT, CONF_DISABLED_BY_DEFAULT,
CONF_DISCOVERY, CONF_DISCOVERY,
CONF_ENTITY_CATEGORY,
CONF_ICON, CONF_ICON,
CONF_ID, CONF_ID,
CONF_INTERNAL, CONF_INTERNAL,
@ -35,6 +37,9 @@ from esphome.const import (
CONF_UPDATE_INTERVAL, CONF_UPDATE_INTERVAL,
CONF_TYPE_ID, CONF_TYPE_ID,
CONF_TYPE, CONF_TYPE,
ENTITY_CATEGORY_CONFIG,
ENTITY_CATEGORY_DIAGNOSTIC,
ENTITY_CATEGORY_NONE,
KEY_CORE, KEY_CORE,
KEY_FRAMEWORK_VERSION, KEY_FRAMEWORK_VERSION,
KEY_TARGET_FRAMEWORK, KEY_TARGET_FRAMEWORK,
@ -1551,6 +1556,17 @@ def maybe_simple_value(*validators, **kwargs):
return validate return validate
_ENTITY_CATEGORIES = {
ENTITY_CATEGORY_NONE: cg.EntityCategory.ENTITY_CATEGORY_NONE,
ENTITY_CATEGORY_CONFIG: cg.EntityCategory.ENTITY_CATEGORY_CONFIG,
ENTITY_CATEGORY_DIAGNOSTIC: cg.EntityCategory.ENTITY_CATEGORY_DIAGNOSTIC,
}
def entity_category(value):
return enum(_ENTITY_CATEGORIES, lower=True)(value)
MQTT_COMPONENT_AVAILABILITY_SCHEMA = Schema( MQTT_COMPONENT_AVAILABILITY_SCHEMA = Schema(
{ {
Required(CONF_TOPIC): subscribe_topic, Required(CONF_TOPIC): subscribe_topic,
@ -1582,6 +1598,7 @@ ENTITY_BASE_SCHEMA = Schema(
Optional(CONF_INTERNAL): boolean, Optional(CONF_INTERNAL): boolean,
Optional(CONF_DISABLED_BY_DEFAULT, default=False): boolean, Optional(CONF_DISABLED_BY_DEFAULT, default=False): boolean,
Optional(CONF_ICON): icon, Optional(CONF_ICON): icon,
Optional(CONF_ENTITY_CATEGORY): entity_category,
} }
) )

View file

@ -203,6 +203,7 @@ CONF_ELSE = "else"
CONF_ENABLE_PIN = "enable_pin" CONF_ENABLE_PIN = "enable_pin"
CONF_ENABLE_TIME = "enable_time" CONF_ENABLE_TIME = "enable_time"
CONF_ENERGY = "energy" CONF_ENERGY = "energy"
CONF_ENTITY_CATEGORY = "entity_category"
CONF_ENTITY_ID = "entity_id" CONF_ENTITY_ID = "entity_id"
CONF_ESP8266_DISABLE_SSL_SUPPORT = "esp8266_disable_ssl_support" CONF_ESP8266_DISABLE_SSL_SUPPORT = "esp8266_disable_ssl_support"
CONF_ESPHOME = "esphome" CONF_ESPHOME = "esphome"
@ -919,3 +920,12 @@ KEY_CORE = "core"
KEY_TARGET_PLATFORM = "target_platform" KEY_TARGET_PLATFORM = "target_platform"
KEY_TARGET_FRAMEWORK = "target_framework" KEY_TARGET_FRAMEWORK = "target_framework"
KEY_FRAMEWORK_VERSION = "framework_version" KEY_FRAMEWORK_VERSION = "framework_version"
# Entity categories
ENTITY_CATEGORY_NONE = ""
# The entity category for configuration values/controls
ENTITY_CATEGORY_CONFIG = "config"
# The entity category for read only diagnostic values, for example RSSI, uptime or MAC Address
ENTITY_CATEGORY_DIAGNOSTIC = "diagnostic"

View file

@ -26,6 +26,10 @@ void EntityBase::set_disabled_by_default(bool disabled_by_default) { this->disab
const std::string &EntityBase::get_icon() const { return this->icon_; } const std::string &EntityBase::get_icon() const { return this->icon_; }
void EntityBase::set_icon(const std::string &name) { this->icon_ = name; } void EntityBase::set_icon(const std::string &name) { this->icon_ = name; }
// Entity Category
EntityCategory EntityBase::get_entity_category() const { return this->entity_category_; }
void EntityBase::set_entity_category(EntityCategory entity_category) { this->entity_category_ = entity_category; }
// Entity Object ID // Entity Object ID
const std::string &EntityBase::get_object_id() { return this->object_id_; } const std::string &EntityBase::get_object_id() { return this->object_id_; }

View file

@ -5,6 +5,12 @@
namespace esphome { namespace esphome {
enum EntityCategory : uint8_t {
ENTITY_CATEGORY_NONE = 0,
ENTITY_CATEGORY_CONFIG = 1,
ENTITY_CATEGORY_DIAGNOSTIC = 2,
};
// The generic Entity base class that provides an interface common to all Entities. // The generic Entity base class that provides an interface common to all Entities.
class EntityBase { class EntityBase {
public: public:
@ -31,6 +37,10 @@ class EntityBase {
bool is_disabled_by_default() const; bool is_disabled_by_default() const;
void set_disabled_by_default(bool disabled_by_default); void set_disabled_by_default(bool disabled_by_default);
// Get/set the entity category.
EntityCategory get_entity_category() const;
void set_entity_category(EntityCategory entity_category);
// Get/set this entity's icon // Get/set this entity's icon
const std::string &get_icon() const; const std::string &get_icon() const;
void set_icon(const std::string &name); void set_icon(const std::string &name);
@ -45,6 +55,7 @@ class EntityBase {
uint32_t object_id_hash_; uint32_t object_id_hash_;
bool internal_{false}; bool internal_{false};
bool disabled_by_default_{false}; bool disabled_by_default_{false};
EntityCategory entity_category_{ENTITY_CATEGORY_NONE};
}; };
} // namespace esphome } // namespace esphome

View file

@ -2,6 +2,7 @@ import logging
from esphome.const import ( from esphome.const import (
CONF_DISABLED_BY_DEFAULT, CONF_DISABLED_BY_DEFAULT,
CONF_ENTITY_CATEGORY,
CONF_ICON, CONF_ICON,
CONF_INTERNAL, CONF_INTERNAL,
CONF_NAME, CONF_NAME,
@ -102,6 +103,8 @@ async def setup_entity(var, config):
add(var.set_internal(config[CONF_INTERNAL])) add(var.set_internal(config[CONF_INTERNAL]))
if CONF_ICON in config: if CONF_ICON in config:
add(var.set_icon(config[CONF_ICON])) add(var.set_icon(config[CONF_ICON]))
if CONF_ENTITY_CATEGORY in config:
add(var.set_entity_category(config[CONF_ENTITY_CATEGORY]))
def extract_registry_entry_config(registry, full_config): def extract_registry_entry_config(registry, full_config):

View file

@ -34,3 +34,4 @@ GPIOPin = esphome_ns.class_("GPIOPin")
InternalGPIOPin = esphome_ns.class_("InternalGPIOPin", GPIOPin) InternalGPIOPin = esphome_ns.class_("InternalGPIOPin", GPIOPin)
gpio_ns = esphome_ns.namespace("gpio") gpio_ns = esphome_ns.namespace("gpio")
gpio_Flags = gpio_ns.enum("Flags", is_class=True) gpio_Flags = gpio_ns.enum("Flags", is_class=True)
EntityCategory = esphome_ns.enum("EntityCategory")