Skip to content

PropertyDescriptionBuilder: check that format is specified for types that require them? #3

@nagisa

Description

@nagisa

Currently the PropertyDescriptionBuilder does not appear to have any failure conditions. However there is at least one condition that a valid property description must satisfy -- if the type is of enum or color, then the format must be specified describing valid variants (for enum) or color formats (for color.)

It looks like today there is nothing preventing an invalid property from being constructed. I can think of a couple of possible avenues here:

  1. Move the field describing the valid values to HomieDataType::Enum and HomieDataType::Color. This makes the format impossible to miss specifying, but at the same time it leads to a weird split between types that have an optional format. It also doesn't directly follow the shape of the description JSON anymore;
  2. Make PropertyDescriptionBuilder::build fallible (return a Result.) It still makes it possible to construct invalid PropertyDescriptions by building the PropertyDescription structure directly due to its public fields, but perhaps that might even be desired -- if only to handle other device implementations which might have not specified their enum/color formats for whatever reason.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions