chrivers / bifrost

Hue Bridge Emulator
GNU General Public License v3.0
124 stars 6 forks source link

Event loop broke: unknown field `icon` #24

Closed Flavien closed 2 months ago

Flavien commented 2 months ago

I am trying Bifrost at the moment, but I am getting this error:

ERROR bifrost::z2m                   > [server1] Event loop broke: unknown field `icon`, expected one of `description`, `exposes`, `model`, `options`, `supports_ota`, `vendor` at line 1 column 424853

I do have a custom converter with an icon field. It might be a good idea to ignore unrecognised fields?

chrivers commented 2 months ago

Uh, this is exciting! Can you tell me a little bit more about this custom converter?

I'm curious how those work, and I haven't seen one with my own eyes yet :smiley:

You're absolutely right, of course, we should ignore unrecognized fields.

Here in the beginning, I've deliberately kept the parsing very strict, to weed out edge cases as quickly as possible.

If you have the chance, can you send me a wscat dump with (at least) the offending data?

It's an example file, so i.e.

# substitute "10.0.0.7:8080" for whatever your z2m websocket address 
cargo run --example=wscat ws://10.0.0.7:8080 > flavien-wscat-$(date -I).log

# (let it run until you've seen the error in bifrost, then ctrl-c)
Flavien commented 2 months ago

It's a device with customisable firmware, and the customisation tool generates a converter based on the features selected. You can see an example of customer converter here (though doesn't have an icon): https://github.com/Koenkk/zigbee2mqtt/discussions/22227

Here is an extract from the logs with the device that's causing the issue: https://gist.github.com/Flavien/95ce4de11e0fe73ab304793813cef658

chrivers commented 2 months ago

Are you okay with testing something, based on git cloning and compiling the project yourself?

If so, try git clone, then edit bifrost/src/z2m/api.rs, and remove line 355:

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)] // <----- that's this one
pub struct Definition {
    pub description: String,
    pub exposes: Vec<Expose>,
    pub model: String,
    pub options: Vec<Expose>,
    pub supports_ota: bool,
    pub vendor: String,
}

After that, build the project as normal (cargo build. Add --release for an optimized build, that will be a lot faster.)

Flavien commented 2 months ago

Yes I tested that already, and as expected it works.

chrivers commented 2 months ago

Thanks for testing :+1:

I'll definitely remove that constraint from Definition - and probably a good few other places. I'll make an update soon

chrivers commented 2 months ago

I've made MR #27 that fixes this :+1: