The bulk of the work a driver does is done inside its general code section. This is where you write methods and members using the Groovy programming language to define how you driver functions. Drivers can be very different depending on what they do. A driver that communicates with a Z-Wave device is going to look very different than one that is a virtual device with nothing physical in the real world or one that communicates over telnet to a LAN device.
This article gives you a general overview of device driver code, but drivers will vary greatly depending on what the device driver is intended to do.
Device drivers can contain a few built-in callback methods that are triggered but the Hubitat environment in response to certain actions.
This method is called when the device is first created and can be used to initialize any device specific configuration and setup.
This method is called when the device is removed to allow for any necessary cleanup.
This method is called when the preferences of a device are updated.
This method is called in response to a message received by the device driver. Depending on the driver this could be from any number of sources. This could be a Z-Wave message, Zigbee message, telnet message, websocket message, etc. Depending on the type of message received you will likely need to parse the
description string into something more useful. The following list of methods are useful for decoding the description:
Event parse(String description)
User-defined methods are where your driver does "everything else." It is where you implement commands, define callbacks for scheduled events, create callbacks for event subscriptions, etc. Essentially you can do just about anything in a user defined method that you can do in a normal Groovy method.