public void HubPropertiesEncoder_Encode_Downstream(HubProperty property, HubPropertyOperation operation, string expectedData) { // act var data = MessageEncoder.Encode(new HubPropertyMessage(property, operation), null); // assert Assert.Equal(expectedData, BytesStringUtil.DataToString(data)); }
public Task RequestHubPropertySingleUpdate(HubProperty property) { AssertIsConnected(); return(Protocol.SendMessageReceiveResultAsync <HubPropertyMessage>(new HubPropertyMessage(property, HubPropertyOperation.RequestUpdate) { HubId = HubId, }, msg => msg.Operation == HubPropertyOperation.Update && msg.Property == property)); }
public async Task ResetHubPropertyAsync(HubProperty property) { if (property != HubProperty.AdvertisingName && property != HubProperty.HardwareNetworkId ) { throw new ArgumentException("Not all properties can be reset (only AdvertisingName, HardwareNetworkId)", nameof(property)); } AssertIsConnected(); await Protocol.SendMessageAsync(new HubPropertyMessage(property, HubPropertyOperation.Reset) { HubId = HubId, }); await RequestHubPropertySingleUpdate(property); }
public async Task SetupHubPropertyNotificationAsync(HubProperty property, bool enabled) { if (property != HubProperty.AdvertisingName && property != HubProperty.Button && property != HubProperty.BatteryVoltage && property != HubProperty.Rssi ) { throw new ArgumentException("Not all properties can be monitored (only AdvertisingName, Button, BatteryVoltage, Rssi)", nameof(property)); } AssertIsConnected(); await Protocol.SendMessageAsync(new HubPropertyMessage(property, enabled ? HubPropertyOperation.EnableUpdates : HubPropertyOperation.DisableUpdates) { HubId = HubId, }); }
public async Task SetHubPropertyAsync <T>(HubProperty property, T value) { if (property != HubProperty.AdvertisingName && property != HubProperty.HardwareNetworkFamily && property != HubProperty.HardwareNetworkId ) { throw new ArgumentException("Not all properties can be set (only AdvertisingName, HardwareNetworkFamily, HardwareNetworkId)", nameof(property)); } AssertIsConnected(); await Protocol.SendMessageAsync(new HubPropertyMessage <T>() { HubId = HubId, Operation = HubPropertyOperation.Set, Property = property, Payload = value, }); await RequestHubPropertySingleUpdate(property); }
public void HubPropertiesEncoder_Decode_UpdateUpstream_StringShim(string messageAsString, HubProperty expectedProperty, HubPropertyOperation expectedPropertyOperation, string payload) => HubPropertiesEncoder_Decode_UpdateUpstream(messageAsString, expectedProperty, expectedPropertyOperation, payload);
//[InlineData("0B-00-01-0D-06-90-84-2B-49-5D-19", HubProperty.PrimaryMacAddress, HubPropertyOperation.Update)] //[InlineData("0B-00-01-0E-06-90-84-2B-83-5D-19", HubProperty.SecondaryMacAddress, HubPropertyOperation.Update, (byte)0)] // HardwareNetworkFamily threw error => UNSPECED public void HubPropertiesEncoder_Decode_UpdateUpstream <T>(string messageAsString, HubProperty expectedProperty, HubPropertyOperation expectedPropertyOperation, T payload) { // arrange var data = BytesStringUtil.StringToData(messageAsString).AsSpan()[3..]; // act var message = new HubPropertiesEncoder().Decode(0x00, data) as HubPropertyMessage <T>; // assert Assert.Equal(expectedProperty, message.Property); Assert.Equal(expectedPropertyOperation, message.Operation); Assert.Equal(payload, message.Payload); }
private IObservable <T> BuildObservableForProperty <T>(IObservable <LegoWirelessMessage> upstreamMessages, HubProperty property) => upstreamMessages .OfType <HubPropertyMessage>() .Where(msg => msg.Operation == HubPropertyOperation.Update && msg.Property == property) .Cast <HubPropertyMessage <T> >() .Select(msg => msg.Payload);