Skip to content

Commit

Permalink
Update alexa networking integration (#2421)
Browse files Browse the repository at this point in the history
Related to openhab/openhab-alexa#660.

Signed-off-by: jsetton <[email protected]>
  • Loading branch information
jsetton authored Feb 28, 2024
1 parent 565844f commit bc7b1e4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,7 @@ export default {
// Networking Attributes
NetworkAccess: {
itemTypes: ['Switch'],
parameters: () => [p.inverted(), p.retrievable()],
visible: (item) => item.groups
.map((group) => group.metadata.alexa.config || {})
.some((config) => !!config.macAddress)
parameters: () => [p.inverted(), p.retrievable()]
},

// Scene Attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ const blindParameters = (_, item) => {
return attributes.every((attr) => metadata.includes(attr)) ? [p.primaryControl()] : []
}

const networkParameters = (_, item) => {
const deviceTypes = ['NetworkHardware', 'Router']
const connection = item.groups.find((g) => deviceTypes.includes(g.metadata.alexa.value))
return connection ? [p.connectedTo(connection.label || connection.name), p.hostname(), p.macAddress()] : []
}

export const defaultParameters = (itemType, item) => {
return itemType === 'Group' || !item.groups.length
? [p.deviceName(item.label), p.deviceDescription(`${itemType} ${item.name}`)]
Expand Down Expand Up @@ -138,8 +132,7 @@ export default {
},
Computer: {
defaultAttributes: ['PowerState'],
supportedAttributes: networkDeviceAttributes,
groupParameters: networkParameters
supportedAttributes: networkDeviceAttributes
},
ContactSensor: {
defaultAttributes: ['ContactDetectionState'],
Expand Down Expand Up @@ -172,8 +165,7 @@ export default {
},
GameConsole: {
defaultAttributes: ['PowerState'],
supportedAttributes: networkDeviceAttributes,
groupParameters: networkParameters
supportedAttributes: networkDeviceAttributes
},
GarageDoor: {
defaultAttributes: ['OpenState'],
Expand All @@ -189,8 +181,7 @@ export default {
},
Laptop: {
defaultAttributes: ['PowerState'],
supportedAttributes: mobileDeviceAttributes,
groupParameters: networkParameters
supportedAttributes: mobileDeviceAttributes
},
Light: {
defaultAttributes: ['PowerState', 'Brightness', 'Color'],
Expand All @@ -206,8 +197,7 @@ export default {
},
MobilePhone: {
defaultAttributes: ['PowerState'],
supportedAttributes: mobileDeviceAttributes,
groupParameters: networkParameters
supportedAttributes: mobileDeviceAttributes
},
MotionSensor: {
defaultAttributes: ['MotionDetectionState'],
Expand Down Expand Up @@ -289,8 +279,7 @@ export default {
},
Tablet: {
defaultAttributes: ['PowerState'],
supportedAttributes: mobileDeviceAttributes,
groupParameters: networkParameters
supportedAttributes: mobileDeviceAttributes
},
Television: {
defaultAttributes: ['PowerState', 'Channel'],
Expand Down Expand Up @@ -319,10 +308,9 @@ export default {
},
Wearable: {
defaultAttributes: ['PowerState'],
supportedAttributes: mobileDeviceAttributes,
groupParameters: networkParameters
supportedAttributes: mobileDeviceAttributes
},
Other: {
supportedAttributes: Object.keys(attributes).filter((attr) => attr !== 'NetworkAccess' && attr !== 'Scene')
supportedAttributes: Object.keys(attributes).filter((attr) => attr !== 'Scene')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,6 @@ export default {
min: 1,
default: (config) => (config.scale || getTemperatureScale(item)) === 'FAHRENHEIT' ? 2 : 1
}),
connectedTo: (value) => ({
name: 'connectedTo',
label: 'Connected To',
type: 'TEXT',
default: value,
readOnly: true
}),
deviceDescription: (defaultValue) => ({
name: 'description',
label: 'Device Description',
Expand Down Expand Up @@ -156,13 +149,6 @@ export default {
max: 255,
advanced: true
}),
hostname: () => ({
name: 'hostname',
label: 'Hostname',
type: 'TEXT',
default: 'N/A',
advanced: true
}),
increment: (defaultValue) => ({
name: 'increment',
label: 'Default Increment',
Expand All @@ -187,13 +173,6 @@ export default {
limitToOptions: true,
advanced: true
}),
macAddress: () => ({
name: 'macAddress',
label: 'MAC Address',
description: 'Formatted as EUI-48 or EUI-64 address with colon or dash separators',
type: 'TEXT',
pattern: '([0-9a-fA-F]{2}(-|:)){7}[0-9a-fA-F]{2}$|^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}'
}),
nonControllable: (stateDescription) => ({
name: 'nonControllable',
label: 'Non-Controllable',
Expand Down Expand Up @@ -350,7 +329,7 @@ export default {
.slice(0, STATE_DESCRIPTION_OPTIONS_LIMIT),
placeholder: placeholder.replace(/,/g, '\n'),
multiple: true,
required: !stateDescription || !stateDescription.options || !stateDescription.options.length
required: !stateDescription?.options?.length
}),
supportedModes: (stateDescription) => ({
name: 'supportedModes',
Expand All @@ -363,7 +342,7 @@ export default {
.slice(0, STATE_DESCRIPTION_OPTIONS_LIMIT),
placeholder: 'Normal=Normal:Cottons\nWhites=Whites',
multiple: true,
required: !stateDescription || !stateDescription.options || !stateDescription.options.length
required: !stateDescription?.options?.length
}),
supportedOperations: () => ({
name: 'supportedOperations',
Expand Down

0 comments on commit bc7b1e4

Please sign in to comment.