Skip to content

Implement onoff for light entities#88

Open
autoSteve wants to merge 14 commits into
masterfrom
Add-onoff-keyword
Open

Implement onoff for light entities#88
autoSteve wants to merge 14 commits into
masterfrom
Add-onoff-keyword

Conversation

@autoSteve

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for an onoff keyword to publish a Home Assistant MQTT light entity that is ON/OFF-only (no brightness slider), and documents the new option.

Changes:

  • Document onoff usage and provide an example configuration in the README.
  • Extend discovery keyword parsing to recognize onoff and emit a simplified MQTT light discovery payload when enabled.
  • Bump the embedded “Downloaded version” string to 1.1.0.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
README.md Documents the new onoff keyword and shows an example for ON/OFF-only light entities.
MQTT send receive.lua Adds onoff to recognized keywords and changes MQTT light discovery payload generation to omit brightness topics when onoff is set.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread MQTT send receive.lua
Comment thread MQTT send receive.lua Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

MQTT send receive.lua:134

  • This change removes support for the legacy includeunit keyword (singular). Since previous versions used includeunit, this is a breaking behavior change for existing installs; consider accepting both spellings to preserve backward compatibility while keeping includeunits as the documented form.
  'includeunits', 'preset', 'noleveltranslate', 'exactpn', 'label', 'onoff'

MQTT send receive.lua:836

  • To preserve backward compatibility for existing configs that used the old includeunit spelling, add a synonym mapping so includeunit is treated as includeunits during tag parsing.
  local synonym = { binarysensor = 'binary_sensor', fanpct = 'fan_pct' }
  local special = { includeunits = false, preset = false, dec = false, noleveltranslate = false, exactpn = false, label = false, onoff = false }

Comment thread README.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

MQTT send receive.lua:862

  • includeunit/includeunits keyword handling looks broken: getKeyValue() applies synonym mapping before checking special, but the synonym maps includeunit -> includeunits while special only defines includeunit. As a result, neither includeunit nor includeunits will ever set special.includeunit, and units will never be appended even when the keyword is present.
  local synonym = { binarysensor = 'binary_sensor', fanpct = 'fan_pct', includeunit = 'includeunits' }
  local special = { includeunit = false, preset = false, dec = false, noleveltranslate = false, exactpn = false, label = false, onoff = false }

Comment thread MQTT send receive.lua Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

MQTT send receive.lua:580

  • In trackTransitions, goto next is used before local variables (closing, rate, increment, etc.) are declared, but the ::next:: label is after those declarations. In Lua 5.2+ this is a compile-time error (a goto cannot jump forward into the scope of locals declared later in the same block). Refactor to avoid goto here and use conditional blocks instead.
  for k, v in pairs(transition) do
    if t < v.ts then goto next end
    local closing = v.state == 'closing'
    if not mqttDevices[k] or not mqttDevices[k].rate then goto next end
    local rate = closing and tonumber(mqttDevices[k].rate[2]) or tonumber(mqttDevices[k].rate[1])
    if not rate then goto next end
    local increment = (t - v.ts) / rate * 256
    if closing then v.level = v.level - increment else v.level = v.level + increment end
    coverLevel[k] = math.floor(v.level + 0.5)
    v.ts = t
    if coverLevel[k] < 0 then coverLevel[k] = 0 elseif coverLevel[k] > 255 then coverLevel[k] = 255 end
    if (coverLevel[k] == 0 and closing) or (coverLevel[k] == 255 and not closing) then kill[k] = true end
    client:publish(mqttReadTopic..k..'/state', v.state, mqttQoS, RETAIN)
    client:publish(mqttReadTopic..k..'/open', coverLevel[k], mqttQoS, RETAIN)
    if logging then log('Publishing state and open '..mqttReadTopic..k..' to '..state..'/'..coverLevel[k]) end
    ::next::
  end

Comment thread MQTT send receive.lua
Comment thread MQTT send receive.lua

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread MQTT send receive.lua Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread MQTT send receive.lua
Comment thread MQTT send receive.lua Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread MQTT send receive.lua Outdated
Comment thread MQTT send receive.lua
Comment thread MQTT send receive.lua

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

MQTT send receive.lua:226

  • parseAddress documents an expected format of net/app/group[/channel], but currently accepts addresses with more than 4 segments (e.g. 1/2/3/4/5) and silently ignores the extra parts. Treat #parts > 4 as invalid to avoid mis-parsing malformed addresses.
  local parts = string.split(address, '/')
  if #parts < 3 then
    log('Error: Invalid '..fieldName..' format for '..name..': '..tostring(address)..', expected format: net/app/group[/channel]')
    return nil, nil, nil, nil
  end

Comment thread MQTT send receive.lua
Comment thread MQTT send receive.lua

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread MQTT send receive.lua
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better integration of non-dimmable lights on relays

2 participants