MCPcopy Create free account
hub / github.com/custom-cards/button-entity-row / setConfig

Method setConfig

button-entity-row.js:79–129  ·  view source on GitHub ↗
(config)

Source from the content-addressed store, hash-verified

77 }
78
79 setConfig(config) {
80 config = JSON.parse(JSON.stringify(config))
81 if (!config.buttons) throw new Error("missing buttons")
82 if (!Array.isArray(config.buttons)) throw new Error("buttons must be an array")
83 if (config.buttons.length <= 0) throw new Error("at least one button required")
84
85 if (!Array.isArray(config.buttons[0])) {
86 config.buttons = [config.buttons]
87 }
88
89 this.config = config
90 this.rows = config.buttons.map(row =>
91 row.map(item => {
92 let button =
93 typeof item === "string"
94 ? {
95 entityId: item,
96 icon: undefined,
97 stateIcons: undefined,
98 stateStyles: undefined,
99 stateIconStyles: undefined,
100 style: undefined,
101 iconStyle: undefined,
102 name: undefined,
103 service: undefined,
104 serviceData: undefined
105 }
106 : {
107 entityId: item.entity,
108 icon: item.icon,
109 stateIcons: item.state_icons,
110 stateStyles: item.state_styles,
111 stateIconStyles: item.state_icon_styles,
112 style: item.style,
113 iconStyle: item.icon_style,
114 name: item.name,
115 service: item.service,
116 serviceData: item.service_data
117 }
118
119 if (!button.service) {
120 button = { ...button, ...this._withDefaultEntityService(button.entityId) }
121 }
122
123 button.serviceData = this._getObjectData(button.serviceData)
124 button.stateIcons = this._getObjectData(button.stateIcons)
125
126 return button
127 })
128 )
129 }
130
131 _withDefaultEntityService(entityId) {
132 const domain = entityId.split(".")[0]

Callers

nothing calls this directly

Calls 2

_getObjectDataMethod · 0.95

Tested by

no test coverage detected