Class: OpenHAB::Core::Items::GenericItem
- Inherits:
-
Object
- Object
- OpenHAB::Core::Items::GenericItem
- Includes:
- Item, Persistence, Semantics, DSL::Items::Ensure::Item, DSL::Items::TimedCommand
- Defined in:
- lib/openhab/core/items/generic_item.rb
Overview
The abstract base class for all items.
Direct Known Subclasses
ContactItem, DateTimeItem, GroupItem, ImageItem, LocationItem, NumberItem, PlayerItem, RollershutterItem, StringItem, SwitchItem
Constant Summary
Constants included from Semantics
Semantics::Equipment, Semantics::Location, Semantics::Point, Semantics::Property, Semantics::Tag
Instance Attribute Summary collapse
-
#category ⇒ String
The item's category.
-
#formatted_state ⇒ String
readonly
Format the item's state according to its state description.
-
#label ⇒ String
The item's descriptive label.
-
#name ⇒ String
readonly
The item's name.
-
#raw_state ⇒ State
readonly
Get the raw item state.
- #state ⇒ State? readonly
-
#tags ⇒ Array<String>
The item's tags.
Attributes included from Semantics
#equipment, #equipment_type, #location, #location_type, #point_type, #property_type, #semantic_type
Attributes included from Item
#accepted_command_types, #accepted_data_types, #all_groups, #channel, #channel_uid, #channel_uids, #channels, #groups, #links, #metadata, #provider, #thing, #things
Instance Method Summary collapse
-
#command(command) ⇒ self?
(also: #command!, #<<)
Send a command to this item.
-
#modify(force: false) { ... } ⇒ Object
Defers notifying openHAB of modifications to multiple attributes until the block is complete.
-
#null? ⇒ true, false
Check if the item state == NULL.
-
#refresh ⇒ Item
Send the REFRESH command to the item.
- #state? ⇒ true, false
-
#undef? ⇒ true, false
Check if the item state == UNDEF.
-
#update(state) ⇒ self?
(also: #update!)
Send an update to this item.
Methods included from Semantics
add, #equipment?, #location?, lookup, #point?, #points, remove, #semantic?, tags
Methods included from Item
#color_item?, #contact_item?, #date_time_item?, #dimmer_item?, #group_item?, #image_item?, #inspect, #link, #location_item?, #member_of?, #number_item?, #player_item?, #rollershutter_item?, #string_item?, #switch_item?, #tagged?, #to_s, #unlink
Methods included from Persistence
#all_states_between, #all_states_since, #average_between, #average_since, #changed_between?, #changed_since?, #count_between, #count_since, #count_state_changes_between, #count_state_changes_since, #delta_between, #delta_since, #deviation_between, #deviation_since, #evolution_rate, #historic_state, #last_update, #maximum_between, #maximum_since, #minimum_between, #minimum_since, #persist, #previous_state, #sum_between, #sum_since, #updated_between?, #updated_since?, #variance_between, #variance_since
Methods included from DSL::Items::Ensure::Ensurable
Instance Attribute Details
#category ⇒ String
The item's category.
266 267 268 269 270 271 272 273 274 |
# File 'lib/openhab/core/items/generic_item.rb', line 266 def category=(value) modify do value = value&.to_s next if category == value @modified = true set_category(value) end end |
#formatted_state ⇒ String (readonly)
Format the item's state according to its state description
This may include running a transformation.
103 104 105 |
# File 'lib/openhab/core/items/generic_item.rb', line 103 def formatted_state GenericItem.item_states_event_builder.get_display_state(self) end |
#label ⇒ String
The item's descriptive label.
|
# File 'lib/openhab/core/items/generic_item.rb', line 66
|
#name ⇒ String (readonly)
The item's name.
|
# File 'lib/openhab/core/items/generic_item.rb', line 62
|
#raw_state ⇒ State (readonly)
81 |
# File 'lib/openhab/core/items/generic_item.rb', line 81 alias_method :raw_state, :state |
#state ⇒ State? (readonly)
Returns openHAB item state if state is not UNDEF or NULL, nil otherwise.
This makes it easy to use with the
Ruby safe navigation operator &.
Use #undef? or #null? to check for those states.
115 116 117 |
# File 'lib/openhab/core/items/generic_item.rb', line 115 def state raw_state if state? end |
#tags ⇒ Array<String> #tags=(values) ⇒ void
The item's tags
288 289 290 291 292 293 294 295 296 297 |
# File 'lib/openhab/core/items/generic_item.rb', line 288 def tags=(values) modify do values = DSL::Items::ItemBuilder.normalize_tags(*values) next if values.to_set == tags.to_set @modified = true remove_all_tags add_tags(values) end end |
Instance Method Details
#command(command) ⇒ self? Also known as: command!, <<
Send a command to this item
When this method is chained after the ensure method, or issued inside an ensure_states block, or after ensure_states! have been called, the command will only be sent if the item is not already in the same state.
The similar method command!
, however, will always send the command regardless of the item's state.
146 147 148 149 150 151 |
# File 'lib/openhab/core/items/generic_item.rb', line 146 def command(command) command = format_command(command) logger.trace "Sending Command #{command} to #{name}" $events.send_command(self, command) Proxy.new(self) end |
#modify(force: false) { ... } ⇒ Object
Defers notifying openHAB of modifications to multiple attributes until the block is complete.
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/openhab/core/items/generic_item.rb', line 227 def modify(force: false) raise ArgumentError, "you must pass a block to modify" unless block_given? return yield if instance_variable_defined?(:@modifying) && @modifying begin provider = self.provider if provider && !provider.is_a?(org.openhab.core.common.registry.ManagedProvider) raise FrozenError, "Cannot modify item #{name} from provider #{provider.inspect}." unless force provider = nil logger.debug("Forcing modifications to non-managed item #{name}") end @modified = false @modifying = true r = yield provider&.update(self) if @modified r ensure @modifying = false end end |
#null? ⇒ true, false
Check if the item state == NULL
|
# File 'lib/openhab/core/items/generic_item.rb', line 119
|
#refresh ⇒ Item
Send the REFRESH command to the item
|
# File 'lib/openhab/core/items/generic_item.rb', line 161
|
#state? ⇒ true, false
88 89 90 |
# File 'lib/openhab/core/items/generic_item.rb', line 88 def state? !raw_state.is_a?(Types::UnDefType) end |
#undef? ⇒ true, false
Check if the item state == UNDEF
|
# File 'lib/openhab/core/items/generic_item.rb', line 123
|
#update(state) ⇒ self? Also known as: update!
Send an update to this item
172 173 174 175 176 177 |
# File 'lib/openhab/core/items/generic_item.rb', line 172 def update(state) state = format_update(state) logger.trace "Sending Update #{state} to #{name}" $events.post_update(self, state) Proxy.new(self) end |