com.highmobility.autoapi.Hood Maven / Gradle / Ivy
/*
* The MIT License
*
* Copyright (c) 2014- High-Mobility GmbH (https://high-mobility.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.highmobility.autoapi;
import com.highmobility.autoapi.property.ByteEnum;
import com.highmobility.autoapi.property.Property;
import static com.highmobility.utils.ByteUtils.hexFromByte;
/**
* The Hood capability
*/
public class Hood {
public static final int IDENTIFIER = Identifier.HOOD;
public static final byte PROPERTY_POSITION = 0x01;
/**
* Get Hood property availability information.
*/
public static class GetStateAvailability extends GetAvailabilityCommand {
/**
* Get every Hood property availability
*/
public GetStateAvailability() {
super(IDENTIFIER);
}
GetStateAvailability(byte[] bytes, @SuppressWarnings("unused") boolean fromRaw) throws CommandParseException {
super(bytes);
}
}
/**
* Get Hood properties
*/
public static class GetState extends GetCommand {
/**
* Get all Hood properties
*/
public GetState() {
super(State.class, IDENTIFIER);
}
GetState(byte[] bytes, @SuppressWarnings("unused") boolean fromRaw) throws CommandParseException {
super(State.class, bytes);
}
}
/**
* The hood state
*/
public static class State extends SetCommand {
Property position = new Property<>(Position.class, PROPERTY_POSITION);
/**
* @return The position
*/
public Property getPosition() {
return position;
}
State(byte[] bytes) throws CommandParseException {
super(bytes);
while (propertyIterator.hasNext()) {
propertyIterator.parseNext(p -> {
switch (p.getPropertyIdentifier()) {
case PROPERTY_POSITION: return position.update(p);
}
return null;
});
}
}
private State(Builder builder) {
super(builder);
position = builder.position;
}
public static final class Builder extends SetCommand.Builder {
private Property position;
public Builder() {
super(IDENTIFIER);
}
public State build() {
return new State(this);
}
/**
* @param position The position
* @return The builder
*/
public Builder setPosition(Property position) {
this.position = position.setIdentifier(PROPERTY_POSITION);
addProperty(this.position);
return this;
}
}
}
public enum Position implements ByteEnum {
CLOSED((byte) 0x00),
OPEN((byte) 0x01),
INTERMEDIATE((byte) 0x02);
public static Position fromByte(byte byteValue) throws CommandParseException {
Position[] values = Position.values();
for (int i = 0; i < values.length; i++) {
Position state = values[i];
if (state.getByte() == byteValue) {
return state;
}
}
throw new CommandParseException("Hood.Position does not contain: " + hexFromByte(byteValue));
}
private final byte value;
Position(byte value) {
this.value = value;
}
@Override public byte getByte() {
return value;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy