Skip to content

Commit 77d5a57

Browse files
authored
alias Item#formatted_state to display_state and transformed_state (openhab#488)
1 parent beb0a1d commit 77d5a57

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

lib/openhab/core/items/item.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,30 @@ def to_s
9191
label || name
9292
end
9393

94-
# @!attribute [r] formatted_state
94+
# @!attribute [r] display_state
9595
#
9696
# Format the item's state according to its state description
9797
#
98-
# This may include running a transformation.
98+
# This may include running a transformation, if one is defined in the
99+
# state description's pattern, otherwise it will format according to the
100+
# pattern. If no state description is defined, the state will simply
101+
# be returned as a string.
102+
#
103+
# @note While this method is also aliased to `#transformed_state` to
104+
# match the field available in the openHAB REST API, unlike the API it
105+
# will always return a value even if the state description has no
106+
# transformation.
99107
#
100108
# @return [String] The formatted state
101109
#
102110
# @example
103-
# logger.info(Exterior_WindDirection.formatted_state) # => "NE (36°)"
111+
# logger.info(Exterior_WindDirection.display_state) # => "NE (36°)"
104112
#
105-
def formatted_state
113+
def display_state
106114
Item.item_states_event_builder.get_display_state(self)
107115
end
116+
alias_method :transformed_state, :display_state
117+
alias_method :formatted_state, :display_state
108118

109119
#
110120
# Send a command to this item

0 commit comments

Comments
 (0)