-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Show user friendly attribute names in picker #7337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bramkragten
merged 8 commits into
home-assistant:dev
from
spacegaier:attr-name-formatting
Nov 10, 2020
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a7c8203
Show user friendly attribute names in picker
spacegaier 8006c45
Move logic to a more central place
spacegaier 056caff
Fix linter issue + use attribute name logic for customize
spacegaier 85308b7
Proper conversion from JS to TS
spacegaier 2506d4f
Dont translate back and forth
bramkragten 80f2dc7
Merge branch 'dev' of https://github.com/home-assistant/frontend into…
spacegaier ad4de46
Remove no longer needed CSS capitalization + proper flex grow attribu…
spacegaier 423c63c
Changes from review
spacegaier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| const hassAttributeUtil = { | ||
| DOMAIN_DEVICE_CLASS: { | ||
| binary_sensor: [ | ||
| "battery", | ||
| "cold", | ||
| "connectivity", | ||
| "door", | ||
| "garage_door", | ||
| "gas", | ||
| "heat", | ||
| "light", | ||
| "lock", | ||
| "moisture", | ||
| "motion", | ||
| "moving", | ||
| "occupancy", | ||
| "opening", | ||
| "plug", | ||
| "power", | ||
| "presence", | ||
| "problem", | ||
| "safety", | ||
| "smoke", | ||
| "sound", | ||
| "vibration", | ||
| "window", | ||
| ], | ||
| cover: [ | ||
| "awning", | ||
| "blind", | ||
| "curtain", | ||
| "damper", | ||
| "door", | ||
| "garage", | ||
| "shade", | ||
| "shutter", | ||
| "window", | ||
| ], | ||
| humidifier: ["dehumidifier", "humidifier"], | ||
| sensor: [ | ||
| "battery", | ||
| "humidity", | ||
| "illuminance", | ||
| "temperature", | ||
| "pressure", | ||
| "power", | ||
| "signal_strength", | ||
| "timestamp", | ||
| ], | ||
| switch: ["switch", "outlet"], | ||
| }, | ||
| UNKNOWN_TYPE: "json", | ||
| ADD_TYPE: "key-value", | ||
| TYPE_TO_TAG: { | ||
| string: "ha-customize-string", | ||
| json: "ha-customize-string", | ||
| icon: "ha-customize-icon", | ||
| boolean: "ha-customize-boolean", | ||
| array: "ha-customize-array", | ||
| "key-value": "ha-customize-key-value", | ||
| }, | ||
| LOGIC_STATE_ATTRIBUTES: {}, | ||
| }; | ||
|
|
||
| // Attributes here serve dual purpose: | ||
| // 1) Any key of this object won't be shown in more-info window. | ||
| // 2) Any key which has value other than undefined will appear in customization | ||
| // config according to its value. | ||
| hassAttributeUtil.LOGIC_STATE_ATTRIBUTES = { | ||
| entity_picture: undefined, | ||
| friendly_name: { type: "string", description: "Name" }, | ||
| icon: { type: "icon" }, | ||
| emulated_hue: { | ||
| type: "boolean", | ||
| domains: ["emulated_hue"], | ||
| }, | ||
| emulated_hue_name: { | ||
| type: "string", | ||
| domains: ["emulated_hue"], | ||
| }, | ||
| haaska_hidden: undefined, | ||
| haaska_name: undefined, | ||
| supported_features: undefined, | ||
| attribution: undefined, | ||
| restored: undefined, | ||
| custom_ui_more_info: { type: "string" }, | ||
| custom_ui_state_card: { type: "string" }, | ||
| device_class: { | ||
| type: "array", | ||
| options: hassAttributeUtil.DOMAIN_DEVICE_CLASS, | ||
| description: "Device class", | ||
| domains: ["binary_sensor", "cover", "humidifier", "sensor", "switch"], | ||
| }, | ||
| assumed_state: { | ||
| type: "boolean", | ||
| domains: [ | ||
| "switch", | ||
| "light", | ||
| "cover", | ||
| "climate", | ||
| "fan", | ||
| "humidifier", | ||
| "group", | ||
| "water_heater", | ||
| ], | ||
| }, | ||
| initial_state: { | ||
| type: "string", | ||
| domains: ["automation"], | ||
| }, | ||
| unit_of_measurement: { type: "string" }, | ||
| }; | ||
|
|
||
| export default hassAttributeUtil; | ||
|
|
||
| // Convert from internal snake_case format to external / user-friendly format | ||
| export function formatAttributeNameOut(value: string): string { | ||
| value = value.replace(/_/g, " ").replace(/\bid\b/g, "ID"); | ||
| return value.charAt(0).toUpperCase() + value.slice(1); | ||
| } | ||
|
|
||
| // Convert from internal snake_case format to external / user-friendly format | ||
| export function formatAttributeNamesOut(value: string[]): string[] { | ||
| return value.map((x) => formatAttributeNameOut(x)); | ||
| } | ||
|
|
||
| // Convert from external / user-friendly format to internal snake_case format | ||
| export function formatAttributeNameIn(value: string): string { | ||
| return String(value) | ||
| .replace(/ /g, "_") | ||
| .replace(/\bID\b/g, "id") | ||
| .toLowerCase(); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.