- Use functions for repeated code blocks. Don't Repeat Yourself (DRY principle)
- Device integrations should strive to be as simple as possible. Get a reading, post an observation, get out. Save any complicated post analysis for the cloud where resources are essentially unlimited and can scale to meet demand.
- Device integrations should strive to be stateless. Although the SDE offers the ability to store properties that persist across invocations, using state always adds complexity.
- Add a lot of log statements. Logging is essential when debugging.
- Keep the syncDevice code hook as performant as possible. The syncDevice code hook gets called whenever code is pushed to the device so it should return as fast as possible for the best experience when iteratively updating code
- Consult the auto-completion in the IDE or the SDE Integration API Reference for all of the available convenient methods. What you are trying to do may already be implemented behind an easy-to-call method.
- Be defensive when communicating with devices. Never assume the device will communicate as expected.
- Use comments to explain what command you are sending to a device especially when the command is a non-human readable format such as hexadecimal
- Strive to collect raw data from the device.
- Avoid randomized logic. Deterministic behavior is always preferred.
- Avoid being too strict in the isDeviceAccessible code hook. If any communication is possible, return true.