diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 61f146ed880f..494ba5b214af 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -102,7 +102,7 @@ repos: pass_filenames: false language: script types: [text] - files: ^(homeassistant/.+/(icons|manifest|strings)\.json|homeassistant/.+/(conditions|quality_scale|services|triggers)\.yaml|homeassistant/brands/.*\.json|script/hassfest/(?!metadata|mypy_config).+\.py|requirements.+\.txt)$ + files: ^(homeassistant/.+/(icons|manifest|strings)\.json|homeassistant/.+/(conditions|quality_scale|services|triggers)\.yaml|homeassistant/brands/.*\.json|script/hassfest/(?!metadata|mypy_config).+\.py|homeassistant/components/sensor/const\.py|requirements.+\.txt)$ - id: hassfest-metadata name: hassfest-metadata entry: script/run-in-env.sh python3 -m script.hassfest -p metadata,docker diff --git a/homeassistant/generated/sensor.json b/homeassistant/generated/sensor.json new file mode 100644 index 000000000000..dec0d0499eb5 --- /dev/null +++ b/homeassistant/generated/sensor.json @@ -0,0 +1,61 @@ +{ + "numeric_device_classes": [ + "absolute_humidity", + "apparent_power", + "aqi", + "area", + "atmospheric_pressure", + "battery", + "blood_glucose_concentration", + "carbon_dioxide", + "carbon_monoxide", + "conductivity", + "current", + "data_rate", + "data_size", + "distance", + "duration", + "energy", + "energy_distance", + "energy_storage", + "frequency", + "gas", + "humidity", + "illuminance", + "irradiance", + "moisture", + "monetary", + "nitrogen_dioxide", + "nitrogen_monoxide", + "nitrous_oxide", + "ozone", + "ph", + "pm1", + "pm10", + "pm25", + "pm4", + "power", + "power_factor", + "precipitation", + "precipitation_intensity", + "pressure", + "reactive_energy", + "reactive_power", + "signal_strength", + "sound_pressure", + "speed", + "sulphur_dioxide", + "temperature", + "temperature_delta", + "volatile_organic_compounds", + "volatile_organic_compounds_parts", + "voltage", + "volume", + "volume_flow_rate", + "volume_storage", + "water", + "weight", + "wind_direction", + "wind_speed" + ] +} diff --git a/script/hassfest/__main__.py b/script/hassfest/__main__.py index bb3de97bb8c4..4601f15defec 100644 --- a/script/hassfest/__main__.py +++ b/script/hassfest/__main__.py @@ -29,6 +29,7 @@ from . import ( mypy_config, quality_scale, requirements, + sensor, services, ssdp, translations, @@ -69,6 +70,7 @@ HASS_PLUGINS = [ mdi_icons, mypy_config, metadata, + sensor, ] ALL_PLUGIN_NAMES = [ diff --git a/script/hassfest/sensor.py b/script/hassfest/sensor.py new file mode 100644 index 000000000000..7f9d8970dc2f --- /dev/null +++ b/script/hassfest/sensor.py @@ -0,0 +1,40 @@ +"""Generate the sensor.json file.""" + +import json + +from homeassistant.components.sensor.const import ( + NON_NUMERIC_DEVICE_CLASSES, + SensorDeviceClass, +) + +from .model import Config, Integration + +PATH = "homeassistant/generated/sensor.json" + + +def _generate() -> str: + """Generate the sensor data.""" + numeric_device_classes = sorted( + device_class.value + for device_class in set(SensorDeviceClass) - NON_NUMERIC_DEVICE_CLASSES + ) + return json.dumps({"numeric_device_classes": numeric_device_classes}, indent=2) + + +def validate(integrations: dict[str, Integration], config: Config) -> None: + """Validate sensor.json.""" + path = config.root / PATH + config.cache["sensor"] = content = _generate() + + if path.read_text() != content + "\n": + config.add_error( + "sensor", + "File sensor.json is not up to date. Run python3 -m script.hassfest", + fixable=True, + ) + + +def generate(integrations: dict[str, Integration], config: Config) -> None: + """Generate sensor.json.""" + path = config.root / PATH + path.write_text(f"{config.cache['sensor']}\n")