diff --git a/homeassistant/components/zwave_js/binary_sensor.py b/homeassistant/components/zwave_js/binary_sensor.py index 71de7270d9a..9d72a804ca0 100644 --- a/homeassistant/components/zwave_js/binary_sensor.py +++ b/homeassistant/components/zwave_js/binary_sensor.py @@ -277,12 +277,6 @@ class ZWaveBooleanBinarySensor(ZWaveBaseEntity, BinarySensorEntity): if self.info.primary_value.command_class == CommandClass.BATTERY else None ) - # Legacy binary sensors are phased out (replaced by notification sensors) - # Disable by default to not confuse users - self._attr_entity_registry_enabled_default = bool( - self.info.primary_value.command_class != CommandClass.SENSOR_BINARY - or self.info.node.device_class.generic.key == 0x20 - ) @property def is_on(self) -> bool | None: diff --git a/homeassistant/components/zwave_js/discovery.py b/homeassistant/components/zwave_js/discovery.py index 403ea5c9746..7c29c89dfab 100644 --- a/homeassistant/components/zwave_js/discovery.py +++ b/homeassistant/components/zwave_js/discovery.py @@ -67,6 +67,8 @@ class ZwaveDiscoveryInfo: platform_data: dict[str, Any] | None = None # additional values that need to be watched by entity additional_value_ids_to_watch: set[str] | None = None + # bool to specify whether entity should be enabled by default + entity_registry_enabled_default: bool = True @dataclass @@ -135,6 +137,8 @@ class ZWaveDiscoverySchema: allow_multi: bool = False # [optional] bool to specify whether state is assumed and events should be fired on value update assumed_state: bool = False + # [optional] bool to specify whether entity should be enabled by default + entity_registry_enabled_default: bool = True def get_config_parameter_discovery_schema( @@ -161,6 +165,7 @@ def get_config_parameter_discovery_schema( property_key_name=property_key_name, type={"number"}, ), + entity_registry_enabled_default=False, **kwargs, ) @@ -428,12 +433,33 @@ DISCOVERY_SCHEMAS = [ ], ), # binary sensors + # When CC is Sensor Binary and device class generic is Binary Sensor, entity should + # be enabled by default + ZWaveDiscoverySchema( + platform="binary_sensor", + hint="boolean", + device_class_generic={"Binary Sensor"}, + primary_value=ZWaveValueDiscoverySchema( + command_class={CommandClass.SENSOR_BINARY}, + type={"boolean"}, + ), + ), + # Legacy binary sensors are phased out (replaced by notification sensors) + # Disable by default to not confuse users + ZWaveDiscoverySchema( + platform="binary_sensor", + hint="boolean", + primary_value=ZWaveValueDiscoverySchema( + command_class={CommandClass.SENSOR_BINARY}, + type={"boolean"}, + ), + entity_registry_enabled_default=False, + ), ZWaveDiscoverySchema( platform="binary_sensor", hint="boolean", primary_value=ZWaveValueDiscoverySchema( command_class={ - CommandClass.SENSOR_BINARY, CommandClass.BATTERY, CommandClass.SENSOR_ALARM, }, @@ -456,13 +482,19 @@ DISCOVERY_SCHEMAS = [ platform="sensor", hint="string_sensor", primary_value=ZWaveValueDiscoverySchema( - command_class={ - CommandClass.SENSOR_ALARM, - CommandClass.INDICATOR, - }, + command_class={CommandClass.SENSOR_ALARM}, type={"string"}, ), ), + ZWaveDiscoverySchema( + platform="sensor", + hint="string_sensor", + primary_value=ZWaveValueDiscoverySchema( + command_class={CommandClass.INDICATOR}, + type={"string"}, + ), + entity_registry_enabled_default=False, + ), # generic numeric sensors ZWaveDiscoverySchema( platform="sensor", @@ -471,12 +503,20 @@ DISCOVERY_SCHEMAS = [ command_class={ CommandClass.SENSOR_MULTILEVEL, CommandClass.SENSOR_ALARM, - CommandClass.INDICATOR, CommandClass.BATTERY, }, type={"number"}, ), ), + ZWaveDiscoverySchema( + platform="sensor", + hint="numeric_sensor", + primary_value=ZWaveValueDiscoverySchema( + command_class={CommandClass.INDICATOR}, + type={"number"}, + ), + entity_registry_enabled_default=False, + ), # numeric sensors for Meter CC ZWaveDiscoverySchema( platform="sensor", @@ -500,6 +540,7 @@ DISCOVERY_SCHEMAS = [ type={"number"}, ), allow_multi=True, + entity_registry_enabled_default=False, ), # sensor for basic CC ZWaveDiscoverySchema( @@ -512,6 +553,7 @@ DISCOVERY_SCHEMAS = [ type={"number"}, property={"currentValue"}, ), + entity_registry_enabled_default=False, ), # binary switches ZWaveDiscoverySchema( @@ -697,6 +739,7 @@ def async_discover_values(node: ZwaveNode) -> Generator[ZwaveDiscoveryInfo, None platform_data_template=schema.data_template, platform_data=resolved_data, additional_value_ids_to_watch=additional_value_ids_to_watch, + entity_registry_enabled_default=schema.entity_registry_enabled_default, ) if not schema.allow_multi: diff --git a/homeassistant/components/zwave_js/entity.py b/homeassistant/components/zwave_js/entity.py index 6df7c8d546b..793eaa435d5 100644 --- a/homeassistant/components/zwave_js/entity.py +++ b/homeassistant/components/zwave_js/entity.py @@ -46,6 +46,9 @@ class ZWaveBaseEntity(Entity): self._attr_unique_id = get_unique_id( self.client.driver.controller.home_id, self.info.primary_value.value_id ) + self._attr_entity_registry_enabled_default = ( + self.info.entity_registry_enabled_default + ) self._attr_assumed_state = self.info.assumed_state # device is precreated in main handler self._attr_device_info = { diff --git a/homeassistant/components/zwave_js/sensor.py b/homeassistant/components/zwave_js/sensor.py index 7c41ad035be..209a5b6d4aa 100644 --- a/homeassistant/components/zwave_js/sensor.py +++ b/homeassistant/components/zwave_js/sensor.py @@ -118,15 +118,6 @@ class ZwaveSensorBase(ZWaveBaseEntity, SensorEntity): self._attr_name = self.generate_name(include_value_name=True) self._attr_device_class = self._get_device_class() self._attr_state_class = self._get_state_class() - self._attr_entity_registry_enabled_default = True - # We hide some of the more advanced sensors by default to not overwhelm users - if self.info.primary_value.command_class in [ - CommandClass.BASIC, - CommandClass.CONFIGURATION, - CommandClass.INDICATOR, - CommandClass.NOTIFICATION, - ]: - self._attr_entity_registry_enabled_default = False def _get_device_class(self) -> str | None: """ diff --git a/tests/components/zwave_js/common.py b/tests/components/zwave_js/common.py index f14842609c5..7177134aa33 100644 --- a/tests/components/zwave_js/common.py +++ b/tests/components/zwave_js/common.py @@ -11,6 +11,8 @@ NOTIFICATION_MOTION_BINARY_SENSOR = ( "binary_sensor.multisensor_6_home_security_motion_detection" ) NOTIFICATION_MOTION_SENSOR = "sensor.multisensor_6_home_security_motion_sensor_status" +INDICATOR_SENSOR = "sensor.z_wave_thermostat_indicator_value" +BASIC_SENSOR = "sensor.livingroomlight_basic" PROPERTY_DOOR_STATUS_BINARY_SENSOR = ( "binary_sensor.august_smart_lock_pro_3rd_gen_the_current_status_of_the_door" ) diff --git a/tests/components/zwave_js/test_sensor.py b/tests/components/zwave_js/test_sensor.py index e368ec1b026..aae7a1c0602 100644 --- a/tests/components/zwave_js/test_sensor.py +++ b/tests/components/zwave_js/test_sensor.py @@ -21,9 +21,11 @@ from homeassistant.helpers import entity_registry as er from .common import ( AIR_TEMPERATURE_SENSOR, + BASIC_SENSOR, ENERGY_SENSOR, HUMIDITY_SENSOR, ID_LOCK_CONFIG_PARAMETER_SENSOR, + INDICATOR_SENSOR, NOTIFICATION_MOTION_SENSOR, POWER_SENSOR, ) @@ -88,6 +90,28 @@ async def test_disabled_notification_sensor(hass, multisensor_6, integration): assert state.attributes["value"] == 8 +async def test_disabled_indcator_sensor( + hass, climate_radio_thermostat_ct100_plus, integration +): + """Test sensor is created from Indicator CC and is disabled.""" + ent_reg = er.async_get(hass) + entity_entry = ent_reg.async_get(INDICATOR_SENSOR) + + assert entity_entry + assert entity_entry.disabled + assert entity_entry.disabled_by == er.DISABLED_INTEGRATION + + +async def test_disabled_basic_sensor(hass, ge_in_wall_dimmer_switch, integration): + """Test sensor is created from Basic CC and is disabled.""" + ent_reg = er.async_get(hass) + entity_entry = ent_reg.async_get(BASIC_SENSOR) + + assert entity_entry + assert entity_entry.disabled + assert entity_entry.disabled_by == er.DISABLED_INTEGRATION + + async def test_config_parameter_sensor(hass, lock_id_lock_as_id150, integration): """Test config parameter sensor is created.""" ent_reg = er.async_get(hass)