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

mqtt: add support for ColorSettingTemperature and ColorSettingHsv #1317

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

nberardi
Copy link
Contributor

I have added support for colored lights in the current MQTT design. In my testing this works with both Z2M and ZHA in Home Assistant.

"aedes": "^0.46.1",
"axios": "^0.23.0",
"axios": "^1.6.7",
Copy link
Owner

Choose a reason for hiding this comment

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

this version of axios adds a 4MB dependency on mime db. it's why I haven't upgraded. I'm actually migrating off axios and using fetch directly since that is in node 18.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted

"aedes": "^0.46.1",
"axios": "^0.23.0",
"axios": "^1.6.7",
"color-convert": "^2.0.1",
Copy link
Owner

Choose a reason for hiding this comment

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

I'd rather not introduce a dependency for a simple function here: from copilot:

function rgbToHsv(r: number, g: number, b: number): [number, number, number] {
    r /= 255, g /= 255, b /= 255;

    let max = Math.max(r, g, b), min = Math.min(r, g, b);
    let h, s, v = max;

    let d = max - min;
    s = max == 0 ? 0 : d / max;

    if (max == min) {
        h = 0; // achromatic
    } else {
        switch (max) {
            case r: h = (g - b) / d + (g < b ? 6 : 0); break;
            case g: h = (b - r) / d + 2; break;
            case b: h = (r - g) / d + 4; break;
        }
        h /= 6;
    }

    return [h, s, v];
}

Copy link
Owner

Choose a reason for hiding this comment

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

this dependency looks relatively small and 1 level deep, so this could be fine. I generally prefer avoiding that on trivial stuff like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have completed this item

@@ -0,0 +1,227 @@
import convert from 'color-convert'
Copy link
Owner

Choose a reason for hiding this comment

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

I think color-util.ts would be a better filename

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@nberardi
Copy link
Contributor Author

nberardi commented Feb 13, 2024 via email

@nberardi
Copy link
Contributor Author

nberardi commented Feb 14, 2024 via email

@nberardi
Copy link
Contributor Author

I have addressed the above requests, and squashed them back into the commit

@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "commonjs",
"module": "Node16",
Copy link
Owner

Choose a reason for hiding this comment

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

I dont think this is correct, you probably want this?

   "module": "CommonJS",
    "moduleResolution": "Node16",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will revert. It was likely troubleshooting that didn’t yield any change.

Copy link
Owner

Choose a reason for hiding this comment

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

I just noticed that my tsconfig is also complaining to change this, so I'm not sure what this is about. wasn't doing that before. might have been a node typings change. I'll investigate further later.

@koush koush merged commit c8b799f into koush:main Feb 15, 2024
@nberardi nberardi deleted the mqtt-colors branch February 16, 2024 14:04
rustyd0g pushed a commit to rustyd0g/scrypted that referenced this pull request Feb 17, 2024
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.

2 participants