public void SetSwitch(short id, bool state) { var relay = (ushort)id; if (state) { device.SetRelay(relay); } else { device.ClearRelay(relay); } shadow = shadow.WithBitSetTo(id, state); }