Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the generation scripts #832

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ disable = [
"locally-disabled",
"too-few-public-methods",
"too-many-public-methods",
"too-many-lines",
]
enable = ["useless-suppression", "use-symbolic-message-instead"]
extension-pkg-allow-list = "pydantic"
Expand Down
7 changes: 6 additions & 1 deletion scripts/generate_multilevel_sensor_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def normalize_scale_definition(scale_definitions: dict[str, dict]) -> dict[str,
if sensor_id in (87, 88):
remove_parenthesis_ = False
sensor_name = enum_name_format(sensor_props["label"], remove_parenthesis_)
sensors[sensor_name] = {"id": sensor_id}
sensors[sensor_name] = {"id": sensor_id, "label": sensor_props["label"]}
if isinstance(scale_def, str):
sensors[sensor_name]["scale"] = normalize_name(
scale_def.replace("$SCALES:", "")
Expand Down Expand Up @@ -164,8 +164,13 @@ def generate_int_enum_base_class(class_name: str, docstring: str) -> list[str]:
"from enum import IntEnum",
'CC_SPECIFIC_SCALE = "scale"',
'CC_SPECIFIC_SENSOR_TYPE = "sensorType"',
"",
]

lines.extend(
[f"{sensor}_PROPERTY = \"{data['label']}\"" for sensor, data in sensors.items()]
)

lines.extend(
generate_int_enum_class_definition(
"MultilevelSensorType",
Expand Down
23 changes: 9 additions & 14 deletions scripts/generate_notification_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def generate_int_enum_class_definition(
get_id_func: Callable | None = None,
docstring_info: str = "",
base_class: str = "IntEnum",
include_missing: bool = False,
) -> list[str]:
"""Generate an IntEnum class definition as an array of lines of string."""
class_def: list[str] = []
Expand All @@ -119,21 +118,19 @@ def generate_int_enum_class_definition(
class_def.append(f" {docstring}")
if enum_ref_url:
class_def.append(f" # {enum_ref_url}")
if include_missing:
class_def.append(" UNKNOWN = -1")
class_def.append(" UNKNOWN = -1")
for _enum_name, _enum_id in sorted(enum_map.items(), key=lambda x: x[0]):
if get_id_func:
_enum_id = get_id_func(_enum_id)
class_def.append(f" {enum_name_format(_enum_name, False)} = {_enum_id}")
if include_missing:
class_def.extend(
[
" @classmethod",
f" def _missing_(cls: type, value: object) -> {class_name}: # noqa: ARG003",
' """Set default enum member if an unknown value is provided."""',
f" return {class_name}.UNKNOWN",
]
)
class_def.extend(
[
" @classmethod",
f" def _missing_(cls: type, value: object) -> {class_name}: # noqa: ARG003",
' """Set default enum member if an unknown value is provided."""',
f" return {class_name}.UNKNOWN",
]
)
return class_def


Expand Down Expand Up @@ -201,7 +198,6 @@ def generate_int_enum_base_class(class_name: str, docstring: str) -> list[str]:
NOTIFICATIONS_URL,
docstring_info=notification_event_name.lower(),
base_class="NotificationEvent",
include_missing=True,
)
)
_notification_type_to_notification_event_map[
Expand All @@ -217,7 +213,6 @@ def generate_int_enum_base_class(class_name: str, docstring: str) -> list[str]:
NOTIFICATIONS_URL,
docstring_info=notification_event_value_name.lower(),
base_class="NotificationEventValue",
include_missing=True,
)
)
_notification_event_to_event_value_map[
Expand Down
89 changes: 89 additions & 0 deletions zwave_js_server/const/command_class/multilevel_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,95 @@
CC_SPECIFIC_SCALE = "scale"
CC_SPECIFIC_SENSOR_TYPE = "sensorType"

ACCELERATION_X_AXIS_PROPERTY = "Acceleration X-axis"
ACCELERATION_Y_AXIS_PROPERTY = "Acceleration Y-axis"
ACCELERATION_Z_AXIS_PROPERTY = "Acceleration Z-axis"
AIR_FLOW_PROPERTY = "Air flow"
AIR_TEMPERATURE_PROPERTY = "Air temperature"
AMMONIA_PROPERTY = "Ammonia"
ANGLE_POSITION_PROPERTY = "Angle position"
APPLIED_FORCE_ON_THE_SENSOR_PROPERTY = "Applied force on the sensor"
ATMOSPHERIC_PRESSURE_PROPERTY = "Atmospheric pressure"
BAROMETRIC_PRESSURE_PROPERTY = "Barometric pressure"
BASIS_METABOLIC_RATE_PROPERTY = "Basis metabolic rate (BMR)"
BLOOD_PRESSURE_PROPERTY = "Blood pressure"
BODY_MASS_INDEX_PROPERTY = "Body Mass Index (BMI)"
BOILER_WATER_TEMPERATURE_PROPERTY = "Boiler water temperature"
BONE_MASS_PROPERTY = "Bone mass"
CARBON_DIOXIDE_LEVEL_PROPERTY = "Carbon dioxide (CO₂) level"
CARBON_MONOXIDE_LEVEL_PROPERTY = "Carbon monoxide (CO) level"
CONDENSER_COIL_TEMPERATURE_PROPERTY = "Condenser Coil temperature"
CURRENT_PROPERTY = "Current"
DEFROST_TEMPERATURE_PROPERTY = "Defrost temperature"
DEW_POINT_PROPERTY = "Dew point"
DIRECTION_PROPERTY = "Direction"
DISCHARGE_LINE_TEMPERATURE_PROPERTY = "Discharge Line temperature"
DISCHARGE_PRESSURE_PROPERTY = "Discharge Pressure"
DISTANCE_PROPERTY = "Distance"
DOMESTIC_HOT_WATER_TEMPERATURE_PROPERTY = "Domestic Hot Water (DHW) temperature"
ELECTRICAL_CONDUCTIVITY_PROPERTY = "Electrical conductivity"
ELECTRICAL_RESISTIVITY_PROPERTY = "Electrical resistivity"
EVAPORATOR_COIL_TEMPERATURE_PROPERTY = "Evaporator Coil temperature"
EXHAUST_TEMPERATURE_PROPERTY = "Exhaust temperature"
FAT_MASS_PROPERTY = "Fat mass"
FORMALDEHYDE_LEVEL_PROPERTY = "Formaldehyde (CH₂O) level"
FREQUENCY_PROPERTY = "Frequency"
GENERAL_PURPOSE_PROPERTY = "General purpose"
HEART_RATE_PROPERTY = "Heart rate"
HEART_RATE_LF_HF_RATIO_PROPERTY = "Heart Rate LF/HF ratio"
HUMIDITY_PROPERTY = "Humidity"
ILLUMINANCE_PROPERTY = "Illuminance"
LEAD_PROPERTY = "Lead"
LIQUID_LINE_TEMPERATURE_PROPERTY = "Liquid Line temperature"
LOUDNESS_PROPERTY = "Loudness"
METHANE_DENSITY_PROPERTY = "Methane (CH₄) density"
MOISTURE_PROPERTY = "Moisture"
MOTION_DIRECTION_PROPERTY = "Motion Direction"
MUSCLE_MASS_PROPERTY = "Muscle mass"
NITROGEN_DIOXIDE_PROPERTY = "Nitrogen dioxide"
OUTSIDE_TEMPERATURE_PROPERTY = "Outside temperature"
OZONE_PROPERTY = "Ozone"
PARTICULATE_MATTER_1_PROPERTY = "Particulate Matter 1"
PARTICULATE_MATTER_10_PROPERTY = "Particulate Matter 10"
PARTICULATE_MATTER_2_5_PROPERTY = "Particulate Matter 2.5"
PERSON_COUNTER_ENTERING_PROPERTY = "Person counter (entering)"
PERSON_COUNTER_EXITING_PROPERTY = "Person counter (exiting)"
POWER_PROPERTY = "Power"
RADON_CONCENTRATION_PROPERTY = "Radon concentration"
RAIN_RATE_PROPERTY = "Rain rate"
RELATIVE_MODULATION_LEVEL_PROPERTY = "Relative Modulation level"
RESPIRATORY_RATE_PROPERTY = "Respiratory rate"
RETURN_AIR_TEMPERATURE_PROPERTY = "Return Air temperature"
RF_SIGNAL_STRENGTH_PROPERTY = "RF signal strength"
ROTATION_PROPERTY = "Rotation"
SEISMIC_INTENSITY_PROPERTY = "Seismic Intensity"
SEISMIC_MAGNITUDE_PROPERTY = "Seismic magnitude"
SMOKE_DENSITY_PROPERTY = "Smoke density"
SOIL_HUMIDITY_PROPERTY = "Soil humidity"
SOIL_REACTIVITY_PROPERTY = "Soil reactivity"
SOIL_SALINITY_PROPERTY = "Soil salinity"
SOIL_TEMPERATURE_PROPERTY = "Soil temperature"
SOLAR_RADIATION_PROPERTY = "Solar radiation"
SUCTION_PRESSURE_PROPERTY = "Suction Pressure"
SULFUR_DIOXIDE_PROPERTY = "Sulfur dioxide"
SUPPLY_AIR_TEMPERATURE_PROPERTY = "Supply Air temperature"
TANK_CAPACITY_PROPERTY = "Tank capacity"
TARGET_TEMPERATURE_PROPERTY = "Target temperature"
TIDE_LEVEL_PROPERTY = "Tide level"
TIME_PROPERTY = "Time"
TOTAL_BODY_WATER_PROPERTY = "Total body water (TBW)"
ULTRAVIOLET_PROPERTY = "Ultraviolet"
VELOCITY_PROPERTY = "Velocity"
VOLATILE_ORGANIC_COMPOUND_LEVEL_PROPERTY = "Volatile Organic Compound level"
VOLTAGE_PROPERTY = "Voltage"
WATER_ACIDITY_PROPERTY = "Water acidity"
WATER_CHLORINE_LEVEL_PROPERTY = "Water Chlorine level"
WATER_FLOW_PROPERTY = "Water flow"
WATER_OXIDATION_REDUCTION_POTENTIAL_PROPERTY = "Water Oxidation reduction potential"
WATER_PRESSURE_PROPERTY = "Water pressure"
WATER_TEMPERATURE_PROPERTY = "Water temperature"
WEIGHT_PROPERTY = "Weight"


class MultilevelSensorType(IntEnum):
"""Enum for known multilevel sensor types."""
Expand Down
6 changes: 6 additions & 0 deletions zwave_js_server/const/command_class/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class NotificationType(IntEnum):
"""Enum for known notification types."""

# https://github.com/zwave-js/node-zwave-js/blob/master/packages/config/config/notifications.json
UNKNOWN = -1
ACCESS_CONTROL = 6
APPLIANCE = 12
CLOCK = 11
Expand All @@ -40,6 +41,11 @@ class NotificationType(IntEnum):
WATER_VALVE = 15
WEATHER_ALARM = 16

@classmethod
def _missing_(cls: type, value: object) -> NotificationType: # noqa: ARG003
"""Set default enum member if an unknown value is provided."""
return NotificationType.UNKNOWN


class NotificationEvent(IntEnum):
"""Common base class for Notification CC states enums."""
Expand Down