Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(discovery): add supported_color_modes to lights #3895

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions api/hass/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ type HassDeviceKey =
| 'config_switch'
| 'config_number'

// https://github.com/home-assistant/core/blob/2e76b1f834ea26ef3e1726930812cb4c2ea82518/homeassistant/components/light/__init__.py#L65C1-L81C48
export type ColorMode =
| 'unknown'
| 'onoff'
| 'brightness'
| 'color_temp'
| 'hs'
| 'xy'
| 'rgb'
| 'rgbw'
| 'rgbww'
| 'white'

const configurations: Record<HassDeviceKey, HassDevice> = {
// Binary sensor https://www.home-assistant.io/components/binary_sensor.mqtt
binary_sensor: {
Expand Down
23 changes: 18 additions & 5 deletions api/lib/Gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AlarmSensorType, SetValueAPIOptions } from 'zwave-js'
import { CommandClasses, ValueID } from '@zwave-js/core'
import * as Constants from './Constants'
import { LogLevel, module } from './logger'
import hassCfg from '../hass/configurations'
import hassCfg, { ColorMode } from '../hass/configurations'
import hassDevices from '../hass/devices'
import { storeDir } from '../config/app'
import { IClientPublishOptions } from 'mqtt'
Expand Down Expand Up @@ -1286,6 +1286,9 @@ export default class Gateway {
cfg.discovery_payload.payload_close = 0
} else {
cfg = utils.copy(hassCfg.light_dimmer)
cfg.discovery_payload.supported_color_modes = [
'brightness',
] as ColorMode[]
cfg.discovery_payload.brightness_state_topic =
getTopic
cfg.discovery_payload.brightness_command_topic =
Expand Down Expand Up @@ -2623,6 +2626,12 @@ export default class Gateway {

const endpoint = currentColorValue.endpoint

const supportedColors: ColorMode[] = []

cfg.discovery_payload.supported_color_modes = supportedColors

supportedColors.push('rgb')

// current color values are automatically added later in discoverValue function
cfg.values = []

Expand All @@ -2646,10 +2655,11 @@ export default class Gateway {
switchValue = `37-${endpoint}-currentValue`
}

/* Find the control switch of the device Brightness or Binary
If multilevel is not there use binary
Some devices use also endpoint + 1 as on/off/brightness... try to guess that too!
*/
/*
Find the control switch of the device Brightness or Binary
If multilevel is not there use binary
Some devices use also endpoint + 1 as on/off/brightness... try to guess that too!
*/
let discoveredStateTopic: string
let discoveredCommandTopic: string

Expand Down Expand Up @@ -2677,12 +2687,14 @@ export default class Gateway {
}

if (brightnessValue) {
supportedColors.push('brightness')
cfg.discovery_payload.brightness_state_topic = discoveredStateTopic
cfg.discovery_payload.brightness_command_topic =
discoveredCommandTopic
cfg.discovery_payload.state_topic = discoveredStateTopic
cfg.discovery_payload.command_topic = discoveredCommandTopic
} else if (switchValue) {
supportedColors.push('onoff')
cfg.discovery_payload.state_topic = discoveredStateTopic
cfg.discovery_payload.command_topic = discoveredCommandTopic

Expand All @@ -2695,6 +2707,7 @@ export default class Gateway {

// if whitevalue exists, use currentColor value to get/set white
if (whiteValue && currentColorValue) {
supportedColors.push('white')
// still use currentColor but change the template
cfg.discovery_payload.color_temp_state_topic =
cfg.discovery_payload.rgb_state_topic
Expand Down
Loading