Difference between revisions of "Device Object"

From Hubitat Documentation
Jump to: navigation, search
(Replaced content with " <big>'''We're moving!''' Please visit http://docs2.hubitat.com for the latest documentation.</big> <big> This document is available at: http://docs2.hubitat.com/en/devel...")
(Tag: Replaced)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The Device object (Technically com.hubitat.app.DeviceWrapper, com.hubitat.app.ChildDeviceWrapper and com.hubitat.app.ParentDeviceWrapper) is composed of methods that allow you to interact with the settings and values of a device.  This object is available to Apps that have been given access via a device selection input, as child devices of Apps and other devices and a driver also has access to this via the device object.
 
  
 +
<big>'''We're moving!''' Please visit http://docs2.hubitat.com for the latest documentation.</big>
  
===<code>currentValue</code>===
+
<big>
:Retrieve the current value of an attribute.  By default this value is cached during a single run of the driver.
+
This document is available at: http://docs2.hubitat.com/en/developer/device-object
 
+
</big>
:;Signature
 
:: <code>Object currentValue(String attributeName)</code>
 
:: <code> Object currentValue(String attributeName, boolean skipCache)</code>
 
 
 
:;Parameters
 
::attributeName - The attribute to get the current value of.
 
::skipCache - Optional, do not use the cached value of the attribute, instead force the system to read the latest from the database.
 
 
 
:;Returns
 
::The current value of an attribute.
 
 
 
 
 
===<code>events</code>===
 
:Retrieve a list of events for the device. By default the maximum number of events returned in the list is 10 which can be overridden by the max option.
 
 
 
:;Signature
 
:: <code>List<Event> events()</code>
 
:: <code>List<Event> events(Map options)</code>
 
 
 
:;Parameters
 
::options - Optional values for getting the list of events.  Possible values:
 
:::''max'' - The maximum number of events to retrieve.
 
 
 
:;Returns
 
::List of Event objects for the device
 
 
 
 
 
===<code>eventsSince</code>===
 
:Retrieve a list of events since a date/time.
 
 
 
:;Signature
 
:: <code>List<Event> eventsSince(Date startDate)</code>
 
:: <code>List<Event> eventsSince(Date startDate, Map options)</code>
 
 
 
:;Parameters
 
:: startDate - The date/time to list events since.
 
::options - Optional values for getting the list of events.  Possible values:
 
:::''max'' - The maximum number of events to retrieve.
 
 
 
:;Returns
 
::A list of Events (defaults to 10 events unless otherwise specified in options)
 
 
 
:;Examples
 
 
 
// Get events since 8:00 am today
 
def events = eventsSince(timeToday("08:00"))
 
 
 
// Get a maximum of 5 events
 
def events = eventsSince(timeToday("08:00"), [max:5])
 
 
 
===<code>getName</code>===
 
:Retrieve the name of the device.
 
 
 
:;Signature
 
:: <code>String getName()</code>
 
 
 
:;Parameters
 
:: none
 
 
 
:;Returns
 
::String - The name of the device
 
 
 
===<code>setName</code>===
 
:Update the name of the device.
 
 
 
:;Signature
 
:: <code>void setName(String name)</code>
 
 
 
:;Parameters
 
::name - the new name for the device.
 
 
 
:;Returns
 
::none
 
 
 
===<code>getLabel</code>===
 
:Retrieve the label of the device.
 
 
 
:;Signature
 
:: <code>String getLabel()</code>
 
 
 
:;Parameters
 
:: none
 
 
 
:;Returns
 
::String - The label of the device
 
 
 
===<code>setLabel</code>===
 
:Update the label of the device.
 
 
 
:;Signature
 
:: <code>void setLabel(String label)</code>
 
 
 
:;Parameters
 
::label - the new label for the device.
 
 
 
:;Returns
 
::none
 
 
 
===<code>hasAttribute</code>===
 
:Determines if the device has the specified attribute. This works for both built-in and custom attributes.
 
 
 
:;Signature
 
::<code>Boolean hasAttribute(String attribute)</code>
 
 
 
:;Parameters
 
::attribute- The attribute to check for.
 
 
 
:;Returns
 
::True if the attribute exists, false otherwise.
 
 
 
===<code>hasCapability</code>===
 
:Determines if the device has the specified capability.
 
 
 
:;Signature
 
::<code>Boolean hasCapability(String capability)</code>
 
 
 
:;Parameters
 
::capability - The capability to check for.
 
 
 
:;Returns
 
::True if the capability exists, false otherwise.
 
 
 
===<code>hasCommand</code>===
 
:Determines if the device has the specified command. This works for both built-in and custom commands.
 
 
 
:;Signature
 
::<code> Boolean hasCommand(String command)</code>
 
 
 
:;Parameters
 
::command - The command to check for.
 
 
 
:;Returns
 
::True if the command exists, false otherwise.
 
 
 
===<code>updateSetting</code>===
 
:Updates the value of a setting (preference) to the specified value. If the setting does not exist, this method will create it.
 
 
 
:;Signature
 
::<code>void updateSetting(String name, Long value)</code>
 
::<code>void updateSetting(String name, Boolean value)</code>
 
::<code>void updateSetting(String name, String value)</code>
 
::<code>void updateSetting(String name, Double value)</code>
 
::<code>void updateSetting(String name, Date value)</code>
 
::<code>void updateSetting(String name, List value)</code>
 
 
 
:;Parameters
 
::name - The name of the setting to update
 
::value - The value to store in the setting
 
 
 
:;Returns
 
::None
 
 
 
===<code>getData</code>===
 
:Get all data values for this device.
 
 
 
:;Signature
 
:: <code>Map getData()</code>
 
 
 
:;Parameters
 
::None
 
 
 
:;Returns
 
::Map - All data values.
 
 
 
===<code>getDataValue</code>===
 
:Get a data value that was set for this device.
 
 
 
:;Signature
 
:: <code>String getDataValue(String name)</code>
 
 
 
:;Parameters
 
::name - The String value of the data item.
 
 
 
:;Returns
 
::String - The value of the data.
 
 
 
===<code>getDeviceDataByName</code>===
 
:DEPRECATED: See getDataValue, this method is a wrapper for getDataValue.
 
 
 
===<code>updateDataValue</code>===
 
:Update or create a data value for this device.
 
 
 
:;Signature
 
:: <code>void updateDataValue(String name, String value)</code>
 
 
 
:;Parameters
 
::name - The name of the data item to store.
 
::value - The value of the data item to store.
 
 
 
:;Returns
 
::None.
 
 
 
===<code>removeDataValue</code>===
 
:Remove a data value from a device.
 
 
 
:;Signature
 
:: <code>void removeDataValue(String name)</code> (Since 2.2.1)
 
 
 
:;Parameters
 
::name - The name of the data item to remove.
 
 
 
:;Returns
 
::None.
 
 
 
==<code>Additional to be documented</code>==
 
List<Event> eventsBetween(Date startDate, Date endDate)
 
List<Event> eventsBetween(Date startDate, Date endDate, Map options = null)
 
List<State> statesSince(String attributeName, Date startDate)
 
List<State> statesSince(String attributeName, Date startDate, Map options = null)
 
void sendEvent(Map properties)
 
void updateSetting(String name, Map options)
 
void removeSetting(String name)
 
void clearSetting(String name)
 
Long getIdAsLong()
 
String getId()
 
String getEndpointId()
 
String getZigbeeId()
 
Hub getHub()
 
Map getData()
 
String getStatus()
 
String getDisplayName()
 
void setDisplayName(String displayName)
 
String getDeviceNetworkId()
 
void setDeviceNetworkId(String dni)
 
State currentState(String attributeName)
 
State currentState(String attributeName, boolean skipCache)
 
Object latestValue(String attributeName)
 
Object latestValue(String attributeName, boolean skipCache)
 
State latestState(String attributeName)
 
State latestState(String attributeName, boolean skipCache)
 
List<State> getCurrentStates()
 
List<Command> getSupportedCommands()
 
List<Attribute> getSupportedAttributes()
 
List<Capability> getCapabilities()
 
Date getLastActivity()
 
Long getParentDeviceId()
 
Long getParentAppId()
 
Boolean getIsComponent()
 
boolean isDisabled()
 

Latest revision as of 04:02, 25 September 2022

We're moving! Please visit http://docs2.hubitat.com for the latest documentation.

This document is available at: http://docs2.hubitat.com/en/developer/device-object