mirror of
https://github.com/home-assistant/frontend.git
synced 2025-06-20 09:06:34 +00:00

* Move featureClassNames to js util * Add tests for featureClassNames * Strip empty feature class names * Move canToggleDomain to js util * Add tests for canToggleDomain * Refactor canToggleDomain to ensure boolean return * Switch to chai assert for richer syntax options * Move canToggleState to js util * Tests for canToggleState * Enable linting for mocha tests * Move stateCardType to js util * Add tests for stateCardType * Move stateMoreInfoType to js util * Tests for stateMoreInfoType * Include mdn Array includes polyfill
11 lines
423 B
JavaScript
11 lines
423 B
JavaScript
// Expects classNames to be an object mapping feature-bit -> className
|
|
export default function featureClassNames(stateObj, classNames) {
|
|
if (!stateObj || !stateObj.attributes.supported_features) return '';
|
|
|
|
const features = stateObj.attributes.supported_features;
|
|
|
|
return Object.keys(classNames).map(feature => (
|
|
(features & feature) !== 0 ? classNames[feature] : ''
|
|
)).filter(attr => attr !== '').join(' ');
|
|
}
|