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

Value Type check for Characteristics #74

Open
soundprojects opened this issue Aug 11, 2022 · 2 comments
Open

Value Type check for Characteristics #74

soundprojects opened this issue Aug 11, 2022 · 2 comments

Comments

@soundprojects
Copy link
Contributor

I think it would be good to have a value type check for characteristics in some way

Now a characteristic value only has to be of a Json Value type but that does allow the user to set a bool where the specification excepts a number, resulting in a panic

@ewilken
Copy link
Owner

ewilken commented Aug 14, 2022

Good point!

@soundprojects
Copy link
Contributor Author

soundprojects commented Aug 14, 2022

I was looking through your handle bar templating code and I am wondering if it would help to make the method:

async fn set_value(&mut self, value: serde_json::Value) -> Result<()> { HapCharacteristic::set_value(&mut self.0, value).await }

in codegen/src/main.rs

Would it be an idea to change the argument type to the unit type that the characteristic expects, and then have your template generate the Value structure inside of the set_value function?

That way you can still have all the generics, but the end user will know exactly what value is expected here and code analyzer will notify them of this as well?

It could also make your template have the unit shown in the documentation. This would make each accessory file have different arguments for this function but it would surely make things more clearer?

Something like:

///This function accepts a bool async fn set_value(&mut self, value: bool) -> Result<()> { HapCharacteristic::set_value(&mut self.0, json!(value)).await }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants