Class: OpenHAB::Core::Items::GenericItem
- Inherits:
-
Object
- Object
- OpenHAB::Core::Items::GenericItem
- Includes:
- Item
- Defined in:
- lib/openhab/core/items/generic_item.rb
Overview
The abstract base class for all items.
Direct Known Subclasses
CallItem, ContactItem, DateTimeItem, GroupItem, ImageItem, LocationItem, NumberItem, PlayerItem, RollershutterItem, StringItem, SwitchItem
Constant Summary
Constants included from Semantics
Semantics::Equipment, Semantics::Location, Semantics::Point, Semantics::Property
Constants included from Persistence
Instance Attribute Summary collapse
-
#category ⇒ String
(also: #icon)
The item's category (icon).
-
#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.
-
#was ⇒ State
readonly
The previous state of the item.
Attributes included from Item
#accepted_command_types, #accepted_data_types, #all_groups, #channel, #channel_uid, #channel_uids, #channels, #command_description, #display_state, #groups, #last_state, #last_state_change, #last_state_update, #links, #metadata, #provider, #state_description, #thing, #things
Attributes included from Semantics
#equipment, #equipment_type, #location, #location_type, #point_type, #property_type, #semantic_type
Instance Method Summary collapse
-
#modify(force: false) {|self| ... } ⇒ Object
Defers notifying openHAB of modifications to multiple attributes until the block is complete.
-
#null? ⇒ true, false
Check if the item state == NULL.
- #state? ⇒ true, false
-
#time_series=(time_series) ⇒ void
Set a new time series.
-
#undef? ⇒ true, false
Check if the item state == UNDEF.
- #was? ⇒ true, false
- #was_null? ⇒ true, false
- #was_undef? ⇒ true, false
Methods included from Item
#call_item?, #color_item?, #command, #contact_item?, #date_time_item?, #dimmer_item?, #group_item?, #image_item?, #inspect, #link, #location_item?, #member_of?, #number_item?, #player_item?, #refresh, #rollershutter_item?, #string_item?, #switch_item?, #tagged?, #to_s, #unlink, #update
Methods included from Semantics
add, #equipment?, #location?, lookup, #point?, #points, remove, #semantic?, tags
Methods included from DSL::Items::Ensure::Ensurable
Methods included from Persistence
#all_states_between, #all_states_since, #all_states_until, #average_between, #average_since, #average_until, #changed_between?, #changed_since?, #changed_until?, #count_between, #count_since, #count_state_changes_between, #count_state_changes_since, #count_state_changes_until, #count_until, #delta_between, #delta_since, #delta_until, #deviation_between, #deviation_since, #deviation_until, #evolution_rate, #evolution_rate_between, #evolution_rate_since, #evolution_rate_until, #historic_state, #last_change, #last_update, #maximum_between, #maximum_since, #maximum_until, #median_between, #median_since, #median_until, #minimum_between, #minimum_since, #minimum_until, #next_change, #next_state, #next_update, #persist, #persisted_state, #previous_state, #remove_all_states_between, #remove_all_states_since, #remove_all_states_until, #riemann_sum_between, #riemann_sum_since, #riemann_sum_until, #sum_between, #sum_since, #sum_until, #updated_between?, #updated_since?, #updated_until?, #variance_between, #variance_since, #variance_until
Methods included from DSL::Items::TimedCommand
Instance Attribute Details
#category ⇒ String Also known as: icon
The item's category (icon).
210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/openhab/core/items/generic_item.rb', line 210 def category=(value) modify do value = value&.to_s next if category == value proxied_self = Proxy.new(self) proxied_self.instance_variable_set(:@modified, true) set_category(value) end end |
#label ⇒ String
The item's descriptive label.
|
|
# File 'lib/openhab/core/items/generic_item.rb', line 48
|
#name ⇒ String (readonly)
The item's name.
|
|
# File 'lib/openhab/core/items/generic_item.rb', line 44
|
#raw_state ⇒ State (readonly)
63 |
# File 'lib/openhab/core/items/generic_item.rb', line 63 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.
84 85 86 |
# File 'lib/openhab/core/items/generic_item.rb', line 84 def state raw_state if state? end |
#tags ⇒ Array<String> #tags=(values) ⇒ void
The item's tags
236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/openhab/core/items/generic_item.rb', line 236 def tags=(values) modify do values = DSL::Items::Tags.normalize(*values) next if values.to_set == tags.to_set proxied_self = Proxy.new(self) proxied_self.instance_variable_set(:@modified, true) remove_all_tags add_tags(values) end end |
Instance Method Details
#modify(force: false) {|self| ... } ⇒ Object
Defers notifying openHAB of modifications to multiple attributes until the block is complete.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/openhab/core/items/generic_item.rb', line 166 def modify(force: false) raise ArgumentError, "you must pass a block to modify" unless block_given? proxied_self = Proxy.new(self) return yield(proxied_self) if proxied_self.instance_variable_get(:@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 proxied_self.instance_variable_set(:@modified, false) proxied_self.instance_variable_set(:@modifying, true) r = yield(proxied_self) provider&.update(self) if proxied_self.instance_variable_get(:@modified) r ensure proxied_self.instance_variable_set(:@modifying, false) end end |
#null? ⇒ true, false
Check if the item state == NULL
|
|
# File 'lib/openhab/core/items/generic_item.rb', line 121
|
#state? ⇒ true, false
70 71 72 |
# File 'lib/openhab/core/items/generic_item.rb', line 70 def state? !raw_state.is_a?(Types::UnDefType) end |
#time_series=(time_series) ⇒ void
This method returns an undefined value.
Set a new time series.
This will trigger a time_series_updated event.
|
|
# File 'lib/openhab/core/items/generic_item.rb', line 129
|
#undef? ⇒ true, false
Check if the item state == UNDEF
|
|
# File 'lib/openhab/core/items/generic_item.rb', line 125
|
#was? ⇒ true, false
103 104 105 |
# File 'lib/openhab/core/items/generic_item.rb', line 103 def was? !last_state.nil? && !last_state.is_a?(Types::UnDefType) end |
#was_null? ⇒ true, false
|
|
# File 'lib/openhab/core/items/generic_item.rb', line 92
|