{"_id":"59d5ac8ad2ae47003211b152","project":"568bdc1483d2061900d86cdc","version":{"_id":"59a72290d61777001b6c42c3","project":"568bdc1483d2061900d86cdc","__v":19,"createdAt":"2017-08-30T20:39:44.453Z","releaseDate":"2017-08-30T20:39:44.453Z","categories":["59a7236e3fe4d90025117c10","59a72eb6cb0db3001b84cfe2","59a734eb757d030019b85af8","59c0243b1b2d07001a9d2b76","59c035e42126e10028effb12","59c06c40df5b3c0010584a13","59c1a5852cabe5002641a3e7","59c2fb00b2b45c0010b7a3d7","59c32ceb9aea850010ac4130","59c32e6e190c90003cb0d12f","59c33affb2b45c0010b7aa23","59c7dfa457bd8200105444dc","59c7e975c50cf30010d712a0","59cffdef0cd4dd0010294d54","59d0622ca91a810032c8f60c","59d06733c1aec60026253065","59d174d44ac471001a07b123","59d5a5e323e6e800103defb2","59ecf1d8ed507c001c52b255"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"0.0.0","version":"0"},"category":{"_id":"59d5a5e323e6e800103defb2","project":"568bdc1483d2061900d86cdc","version":"59a72290d61777001b6c42c3","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-10-05T03:24:19.328Z","from_sync":false,"order":3,"slug":"data-modeling-with-service-classes","title":"Data Modeling With Service Classes"},"user":"58cc41f21751ce2f003be3b7","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-10-05T03:52:42.064Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"# Overview\n\nDevice modeling defines the capabilities of a device using models. These models describe the set of commands that a device can execute, and eliminate the need to define customized protocols for every new device connected to the system.\n\nDevices are modeled in Droplit ecosystems by using service classes. Service classes are templates that define device capabilities in a standardized way. They can define events, methods, or properties. The information pieces defined by a service class are collectively known as service members.\n\nService classes group related functionalities into a single template, and provide a common interface to those functions. The specific implementation of a service class on a given device is simply called a service. A device may implement a single service, multiple different services, or multiple instances of the same service for different uses, depending on how the device operates.\n\n# Service Members\n\n## Properties\n\nProperties describe the state of a single device attribute. For example, a “switch” property could indicate if a device is on or off. Properties are stateful, because they have a value that can be both read and written. Writing to a device property will cause the device to change state, and any changes to a device’s underlying state will propagate a state change notification through its exposed properties. This state change may simply be a change in internal information, or it may cause a visible external change in the device, such as turning the device on.\n\n## Methods\n\nMethods execute a device action. For example, a “brew” method on a coffee maker could cause the brewing process to begin. Methods are not stateful, because they do not have any stored values associated with them. They may cause the values of properties to change, but are not required to, and it is not necessary to always associate a method with a specific property. Some methods can accept parameters. No methods can accept return values at the present time, but they will be able to in the future.\n\n## Events\n\nEvents indicate when something takes place on a device. For example, a “motion” event on a motion sensor could indicate that the device detected motion. Events are not stateful. They fire only once, when the event first takes place on the device. Defining events for property changes is not necessary, because all property changes automatically fire an event.\n\n# Defining Services\n\nServices are defined with a single JSON file. The service definition is a JSON object, which must have the following structure.\n\n```\n{\n\t\"name\": \"SERVICE-CLASS-NAME\",\n\t\"properties\": {},\n\t\"methods\": {},\n\t\"events\": {}\n}\n```\n\nThe simplest possible service class contains only a name, and no keys which describe members. A service class name may not contain spaces, and the definitions of service members must be valid JSON.\n\nThe name of the JSON file does not matter, because the name defined in the JSON object is what defines the internal name of the service. Service names must meet the following format requirements.\n\n- Between 1 and 23 characters\n- Only contains characters `A-Z`, `a-z`, `0-9`, `_`\n- No speaces\n- Case-sensitive\n\nBy convention, a service class name is written using the PascalCase capitalization style. Other keys should be written in the camelCase capitalization style.\n\nService definitions can be viewed and updated using the Droplit command line console or the Droplit REST API.","excerpt":"","slug":"services","type":"basic","title":"Service Classes"}
# Overview Device modeling defines the capabilities of a device using models. These models describe the set of commands that a device can execute, and eliminate the need to define customized protocols for every new device connected to the system. Devices are modeled in Droplit ecosystems by using service classes. Service classes are templates that define device capabilities in a standardized way. They can define events, methods, or properties. The information pieces defined by a service class are collectively known as service members. Service classes group related functionalities into a single template, and provide a common interface to those functions. The specific implementation of a service class on a given device is simply called a service. A device may implement a single service, multiple different services, or multiple instances of the same service for different uses, depending on how the device operates. # Service Members ## Properties Properties describe the state of a single device attribute. For example, a “switch” property could indicate if a device is on or off. Properties are stateful, because they have a value that can be both read and written. Writing to a device property will cause the device to change state, and any changes to a device’s underlying state will propagate a state change notification through its exposed properties. This state change may simply be a change in internal information, or it may cause a visible external change in the device, such as turning the device on. ## Methods Methods execute a device action. For example, a “brew” method on a coffee maker could cause the brewing process to begin. Methods are not stateful, because they do not have any stored values associated with them. They may cause the values of properties to change, but are not required to, and it is not necessary to always associate a method with a specific property. Some methods can accept parameters. No methods can accept return values at the present time, but they will be able to in the future. ## Events Events indicate when something takes place on a device. For example, a “motion” event on a motion sensor could indicate that the device detected motion. Events are not stateful. They fire only once, when the event first takes place on the device. Defining events for property changes is not necessary, because all property changes automatically fire an event. # Defining Services Services are defined with a single JSON file. The service definition is a JSON object, which must have the following structure. ``` { "name": "SERVICE-CLASS-NAME", "properties": {}, "methods": {}, "events": {} } ``` The simplest possible service class contains only a name, and no keys which describe members. A service class name may not contain spaces, and the definitions of service members must be valid JSON. The name of the JSON file does not matter, because the name defined in the JSON object is what defines the internal name of the service. Service names must meet the following format requirements. - Between 1 and 23 characters - Only contains characters `A-Z`, `a-z`, `0-9`, `_` - No speaces - Case-sensitive By convention, a service class name is written using the PascalCase capitalization style. Other keys should be written in the camelCase capitalization style. Service definitions can be viewed and updated using the Droplit command line console or the Droplit REST API.