Skip to content

Do the Additions outweigh the mess?#11

Open
d8ahazard wants to merge 37 commits intodotMorten:masterfrom
d8ahazard:master
Open

Do the Additions outweigh the mess?#11
d8ahazard wants to merge 37 commits intodotMorten:masterfrom
d8ahazard:master

Conversation

@d8ahazard
Copy link

I'll be the first to admit, I made a mess with this one.

Generally, when I do pull requests, I try to be a lot more fastidious about separating out features from reformatting and code cleanup, but in this case, there was just so much, it's going to be really hard to do without another git rebase, and then trying to cherry-pick out commits.

I'm not sure if you'd like to review all the things I've done and then pull it in as you see fit, or just merge it all and do a version bump, or what...but I did at the very least try to revert any breaking changes I made...except for re-factoring "Color" to "LifxColor", which I think is a useful enough addition to warrant one breaking change.

The new LifxColor class serves as both a wrapper for standard System.Drawing.Color functions, and also as a simple way to convert between HSBK/RGB/HSL color values.

Additionally, I've created a new "Payload" class that allows for rapid and clean serialization/deserialization of message values...and implemented it everywhere. Works wonderfully.

Aside from new classes and cleanup...I've added support for all of the messages described in the Lifx Documentation, which was greatly aided by the new Payload class.

As such, I've also added support for all of the various Lifx Devices. All the multizone stuff, tile support, and switches.

However, one thing I'm kind of iffy on, or where I didn't follow the model you had started with - is "other" devices. I see you have a base "device" class, and then "LightBulb" for bulbs...but I did not create classes for the other devices, as there didn't seem to be a "clean" way to enumerate the device type on discovery. I tried it - it broke things.

So, that's one thing I'd like to do, but not sure the right approach. Ideally, in my mind, Discovery returns a list of specifically classed devices so the user knows what features are available. Otherwise, option B would be to make all devices generic devices, and then make the user responsible for determining what capabilities a device has.

Similarly...I was thinking that it might be good to have all messages return an Acknowledgement if applicable...versus just discarding them?

So, consider this more of a "Hey, let's talk about this stuff" versus a cut-and-dry PR. I'd like to do this right and keep the library in your hands.

…em.drawing.color, add new tricks

This bugs me.

Also, make LifxColor a class that can handle RGB and HSB values seamlessly, versus having to do weird stuff to convert between.
First of several new additions - this is for zoned devices.
Start adding necessary methods to control multi-zone devices.
Generic linting. Fix names, privacy declarations, other misc stuff.
Add legacy zone setters/getters, response messages.
Now we can just serialize any color directly to a bytewise HSBK value.
…es()

Convert else/if to switch, add option to serialize LifxColor directly, instead of having to do it before calling our broadcast method.
Use proper variable types everywhere as specified by Lifx docs.
Code cleanup
Bump .net standard version to 2.0, update project details.
Add "Payload" class to handle smarter/cleaner parsing of responses from Lifx with auto error-handling and logging.
Add tile message types.
Add tile response types.
Split devices into their own classes for easier management.
Create TileGroup, Switch, and Strip device types, instead of calling everything "bulb".
Add device product check on discovery to determine proper device type to return.
Update readme
Add default initializer for LifxColor.
This should be a near-100% complete set of features, as per the official documentation
Function should return a StateColorZones, not LifxResponse.
It would probably be "better" to create an individual device class for each one, but that requires an additional call to the device to figure out what it is, which seems to be a bit out of scope for the library currently.

So, instead, we'll just use the generic "device".
Update logs in netcore sample app to provide more info so we can remotely debug issues.
Update object passed to device calls (device vs. bulb)
@d8ahazard
Copy link
Author

@dotMorten - So, it's been 15 days since I submitted this...have you had a chance to review it at all?

@dotMorten
Copy link
Owner

dotMorten commented Mar 3, 2021

have you had a chance to review it at all?

No I have not (obviously ;-) ).
Sorry but this is a sparetime project that I make nothing on. Don't always have the time or energy.
Especially when the PR contains a bunch of irrelevant changes and breaking changes. You said it yourself above that it's a mess, and the mess only make it way worse for me to to try and gauge what your PR is doing.

d8ahazard added 10 commits March 9, 2021 11:46
Make StateMultizoneRequest return StateMultiZone response, versus StateZone response.
Ensure payload can properly serialize a tile and datetime.
Testing encoding/decoding of responses when you don't actually own any Lifx Devices is pretty hard, so I created a simple "LifxEmulator" app that can sit within a LAN and respond to messages from LifxNet like a real device.

Some emulation features are still WIP, but the majority of "the things" work.
Make the .netcore app return basic info about switch/tile/multizone devices if discovered.
Thanks to a few intrepid users who collected me "proper" packet responses from Lifx Tile devices, we now have Chain responses working properly.
Use proper terminology when describing payload methods.
Make _data readonly.
Because the command is buffered, we can choose whether to apply it immediately or not.
@d8ahazard
Copy link
Author

have you had a chance to review it at all?

No I have not (obviously ;-) ).
Sorry but this is a sparetime project that I make nothing on. Don't always have the time or energy.
Especially when the PR contains a bunch of irrelevant changes and breaking changes. You said it yourself above that it's a mess, and the mess only make it way worse for me to to try and gauge what your PR is doing.

I understand the time constraints. At this point, a week later, the disparity between our repositories only continues to grow.

As it's going to be incredibly difficult to examine the code directly, the best I can do is summarize:

  1. Add all missing device functions. Tiles, multizone, switches...everything is added.

  2. Add a custom "payload" class that wraps the functionality of the MemoryStream class, and provides a simple way of creating/parsing message payloads. This has been put into the app everywhere, as the new methods are using it as well.

  3. Refactor "Color" to "LifxColor" and add other helper methods. This is the only breaking change I should have introduced, and my reasoning is pretty sound. In any other projects that use System.Drawing.Color, there's now an overlap between the normal system class and the Lifx class. By refactoring, to "LifxColor", there becomes a clear distinction between the classes, and we can use System.Drawing.Color internally, as LifxColor now has a constructor based on it.

  4. Update the core test app to enumerate information on "other" devices, just to validate multi zone info, tile chains, and switch relay states.

  5. Add a "colorSendTest" app to the test apps, which can be used to demonstrate sending colors to various devices.

  6. Add a "LifxEmulator" app, which can be used to test functionality without owning devices.

So, while it looks like a lot of stuff, the end result isn't really that many changes...

Add methods to retrieve Lifx Color formatted values directly.
Make documentation more useful
Replace HSB conversion method.
This one only needs the device and color, and an optional transition time in MS...
public string GetString(long length = -1) {
if (length == -1) length = _len - 1 - _ms.Position;
try {
return _br.ReadChars((int) length).ToString();
Copy link

@tombiddulph tombiddulph Mar 15, 2021

Choose a reason for hiding this comment

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

I think that this should be return new string(_br.ReadChars((int) length)); . As it stands, this line returns the typename eg System.Char[] when it's called via LifxClient.GetDeviceLabelAsync()

client = await LifxNet.LifxClient.CreateAsync();
client.DeviceDiscovered += Client_DeviceDiscovered;
client.DeviceLost += Client_DeviceLost;
client = new LifxClient();

Choose a reason for hiding this comment

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

This line is wrong, the only LifxClient constructor is marked as Private

{
private LifxClient() {
IPEndPoint end = new IPEndPoint(IPAddress.Any, Port);
_socket = new UdpClient(end) {Client = {Blocking = false}, DontFragment = true};

Choose a reason for hiding this comment

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

DontFragment = true throws a NotSupported exception with .NET 5 on MacOs Big Sur. Setting the property to false seems to cure the issue.

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.

3 participants

Comments