no more $smType in webapp

This commit is contained in:
ari committed 2022-05-13 17:26:44 -04:00
1 parent 429dfd5b50
commit c118ccc99b
20 files changed
+327 -502

No files matched your search

+29 -63
View File
@@ -10,18 +10,14 @@ test('converting time to a string', () => {
test('using alias as description', () => {
expect(getDescriptionFromAutomationNode({
$smType: "action",
action: "service",
action_data: {
alias: "Start Music In Kitchen",
service: 'media_player.play_media',
target: {
entity_id: "media_player.kitchen_dot"
},
data: {
media_content_id: "Good Morning",
media_content_type: "SPOTIFY",
}
alias: "Start Music In Kitchen",
service: 'media_player.play_media',
target: {
entity_id: "media_player.kitchen_dot"
},
data: {
media_content_id: "Good Morning",
media_content_type: "SPOTIFY",
}
})).toEqual("Start Music In Kitchen")
})
@@ -29,30 +25,22 @@ test('using alias as description', () => {
test('get service action description', () => {
expect(getDescriptionFromAutomationNode({
$smType: "action",
action: "service",
action_data: {
service: 'media_player.play_media',
target: {
entity_id: "media_player.kitchen_dot"
},
data: {
media_content_id: "Good Morning",
media_content_type: "SPOTIFY",
}
service: 'media_player.play_media',
target: {
entity_id: "media_player.kitchen_dot"
},
data: {
media_content_id: "Good Morning",
media_content_type: "SPOTIFY",
}
})).toEqual("media_player.play_media")
})
test('get repeat action description', () => {
expect(getDescriptionFromAutomationNode({
$smType: "action",
action: "repeat",
action_data: {
repeat: {
count: 10,
sequence: []
}
repeat: {
count: 10,
sequence: []
}
})).toEqual("Repeat 10")
})
@@ -60,57 +48,35 @@ test('get repeat action description', () => {
test('get wait action description', () => {
expect(getDescriptionFromAutomationNode({
$smType: "action",
action: "wait",
action_data: {
wait_template: "states(switch.kitchen_light) == 'on'"
}
wait_template: "states(switch.kitchen_light) == 'on'"
})).toEqual("Wait on states(switch.kitchen_light) == 'on'")
expect(getDescriptionFromAutomationNode({
$smType: "action",
action: "wait",
action_data: {
wait_template: "states(switch.kitchen_light) == 'on'",
// timeout: '00:01:00',
timeout: {
'minutes': 1,
}
wait_template: "states(switch.kitchen_light) == 'on'",
timeout: {
'minutes': 1,
}
})).toEqual("Wait on states(switch.kitchen_light) == 'on' for 00:01:00:00")
})
test('get fire event action description', () => {
expect(getDescriptionFromAutomationNode({
$smType: 'action',
action: 'event',
action_data: {
event: 'test_event',
event_data: {},
}
event: 'test_event',
event_data: {},
})).toEqual("Trigger test_event")
})
test('get device action description', () => {
expect(getDescriptionFromAutomationNode({
$smType: 'action',
action: 'device',
action_data: {
device_id: "12310das01231",
domain: "zwave_js",
type: "set_value"
}
device_id: "12310das01231",
domain: "zwave_js",
type: "set_value"
})).toEqual("set_value on 12310das01231")
})
test('get choose action description', () => {
expect(getDescriptionFromAutomationNode({
$smType: 'action',
action: 'choose',
action_data: {
choose: [],
default: [],
}
choose: [],
default: [],
})).toEqual("Choose")
})
+30 -35
View File
@@ -10,36 +10,13 @@ export const convertTimeToString = ({
}: AutomationTime) => [hours, minutes, seconds, milliseconds].map(n => String(n).padStart(2, '0')).join(':')
export const getDescriptionFromAutomationNode = <N extends AutomationNodeTypes>(node: AutomationNode<N>): string => {
if ('$smType' in node) {
switch (node['$smType']) {
case "action":
if (node.action_data.alias) {
return node.action_data.alias;
}
switch (node.action) {
case 'service':
return node.action_data.service
case 'repeat':
return 'Repeat ' + node.action_data.repeat.count;
case 'wait':
let out = 'Wait on ' + node.action_data.wait_template;
if (node.action_data.timeout) {
out += (' for ' + convertTimeToString(node.action_data.timeout))
}
return out;
case 'event':
return `Trigger ${node.action_data.event}`
case 'device':
return `${node.action_data.type} on ${node.action_data.device_id}`
case 'choose':
return "Choose"
}
}
return 'n/a'
} else if ('condition' in node) {
if (node.alias) {
return node.alias;
}
if (node.alias) {
return node.alias;
}
if ('platform' in node) {
return node.platform
}
if ('condition' in node) {
if (
(node.condition === 'and') ||
(node.condition === 'or') ||
@@ -71,12 +48,30 @@ export const getDescriptionFromAutomationNode = <N extends AutomationNodeTypes>(
return 'n/a'
}
}
} else {
if (node.alias) {
return node.alias;
}
return node.platform
}
if ('service' in node) {
return node.service
}
if ('repeat' in node) {
return 'Repeat ' + node.repeat.count
}
if ('wait_template' in node) {
let out = 'Wait on ' + node.wait_template;
if (node.timeout) {
out += (' for ' + convertTimeToString(node.timeout))
}
return out;
}
if ('event' in node) {
return `Trigger ${node.event}`
}
if ('device_id' in node) {
return `${node.type} on ${node.device_id}`
}
if ('choose' in node) {
return "Choose"
}
return 'n/a'
}
export const prettyEntityId = (entityId: string | string[]) => {
+8 -12
View File
@@ -38,18 +38,14 @@ export const createMockAuto = (tags: Record<string, string> = {}): AutomationDat
]
},
{
$smType: "action",
action: "service",
action_data: {
alias: "Start Music In Kitchen",
service: 'media_player.play_media',
target: {
entity_id: "media_player.kitchen_dot"
},
data: {
media_content_id: "Good Morning",
media_content_type: "SPOTIFY",
}
alias: "Start Music In Kitchen",
service: 'media_player.play_media',
target: {
entity_id: "media_player.kitchen_dot"
},
data: {
media_content_id: "Good Morning",
media_content_type: "SPOTIFY",
}
}
]