Skip to content

Commit

Permalink
Merge branch 'master' into mqtt-discovery-scene
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Jan 22, 2024
2 parents c3a2629 + 3048fed commit cf23f26
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
27 changes: 27 additions & 0 deletions api/hass/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type HassDeviceKey =
| 'thermostat'
| 'fan'
| 'sound_switch'
| 'config_switch'
| 'config_number'

const configurations: Record<HassDeviceKey, HassDevice> = {
// Binary sensor https://www.home-assistant.io/components/binary_sensor.mqtt
Expand Down Expand Up @@ -218,6 +220,31 @@ const configurations: Record<HassDeviceKey, HassDevice> = {
speed_value_template: '{{ value_json.value | int }}',
},
},

config_switch: {
type: 'switch',
object_id: 'config_switch',
discovery_payload: {
payload_off: '0',
payload_on: '1',
value_template: '{{ value_json.value }}',
command_topic: true,
enabled_by_default: false,
entity_category: 'config',
},
},

// https://www.home-assistant.io/integrations/number.mqtt
config_number: {
type: 'number',
object_id: 'config_number',
discovery_payload: {
value_template: '{{ value_json.value }}',
command_topic: true,
enabled_by_default: false,
entity_category: 'config',
},
},
}

export default configurations
44 changes: 44 additions & 0 deletions api/lib/Gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,50 @@ export default class Gateway {
}
break
}
case CommandClasses.Configuration: {
if (!valueId.writeable) {
return
}
let type = valueId.type
if (
type === 'number' &&
valueId.min === 0 &&
valueId.max === 1
) {
type = 'boolean'
}
switch (type) {
case 'boolean':
cfg = utils.copy(hassCfg.config_switch)

// Combine unique Object id, by using all possible scenarios
cfg.object_id = utils.joinProps(
cfg.object_id,
valueId.property,
valueId.propertyKey,
)
break
case 'number':
cfg = utils.copy(hassCfg.config_number)

// Combine unique Object id, by using all possible scenarios
cfg.object_id = utils.joinProps(
cfg.object_id,
valueId.property,
valueId.propertyKey,
)
if (valueId.min !== 1) {
cfg.discovery_payload.min = valueId.min
}
if (valueId.max !== 100) {
cfg.discovery_payload.max = valueId.max
}
break
default:
return
}
break
}
default:
return
}
Expand Down
1 change: 1 addition & 0 deletions api/lib/ZwaveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ export type HassDevice = {
| 'lock'
| 'switch'
| 'fan'
| 'number'
object_id: string
discovery_payload: { [key: string]: any }
discoveryTopic?: string
Expand Down

0 comments on commit cf23f26

Please sign in to comment.