Skip to content

Commit

Permalink
Merge pull request #206 from Smarteon/calendar
Browse files Browse the repository at this point in the history
Add update entry command to calendar api
  • Loading branch information
jimirocks authored Sep 22, 2023
2 parents 112ff65 + 32f020a commit d0b1a75
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 20 deletions.
16 changes: 15 additions & 1 deletion src/main/java/cz/smarteon/loxone/calendar/CalEntryBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public abstract class CalEntryBase {

protected static final String CREATE_ENTRY = "calendarcreateentry/";
protected static final String DELETE_ENTRY = "calendardeleteentry/";
protected static final String UPDATE_ENTRY = "calendarupdateentry/";

/**
* UUID of this calendar entry, should be unique.
Expand Down Expand Up @@ -95,5 +96,18 @@ public CalendarCommand<EmptyValue> deleteEntryCommand(){
*
* @return create calendar entry command
*/
abstract public CalendarCommand<EmptyValue> createEntryCommand();
public CalendarCommand<EmptyValue> createEntryCommand() {
return new CalendarCommand<>(CREATE_ENTRY + this, EmptyValue.class);
}

/**
* Creates update calendar entry command.
* Command updates an existing calendar entry with the given parameters.
*
* @return update calendar entry command
* @param uuid - uuid of an existing entry to be updated
*/
public CalendarCommand<EmptyValue> updateEntryCommand(LoxoneUuid uuid) {
return new CalendarCommand<>(UPDATE_ENTRY + uuid + "/" + this, EmptyValue.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import cz.smarteon.loxone.LoxoneUuid;
import cz.smarteon.loxone.user.EmptyValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -85,7 +84,8 @@ public CalEntryDayOfWeek(
this.weekDayInMonth = weekDayInMonth.value;
}

public CalendarCommand<EmptyValue> createEntryCommand(){
return new CalendarCommand<>(CREATE_ENTRY + name + "/" + operatingMode + "/" + CAL_MODE + "/" + weekDayInMonth + "/" + weekDay + "/" + startMonth, EmptyValue.class);
@Override
public String toString() {
return name + "/" + operatingMode + "/" + CAL_MODE + "/" + weekDayInMonth + "/" + weekDay + "/" + startMonth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import cz.smarteon.loxone.LoxoneUuid;
import cz.smarteon.loxone.user.EmptyValue;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -46,7 +45,8 @@ public CalEntryEasterOffset(
this.easterOffset = easterOffset;
}

public CalendarCommand<EmptyValue> createEntryCommand(){
return new CalendarCommand<>(CREATE_ENTRY + name + "/" + operatingMode + "/" + CAL_MODE + "/" + easterOffset, EmptyValue.class);
@Override
public String toString() {
return name + "/" + operatingMode + "/" + CAL_MODE + "/" + easterOffset;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import cz.smarteon.loxone.LoxoneUuid;
import cz.smarteon.loxone.user.EmptyValue;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -55,7 +54,8 @@ public CalEntryEveryYear(
this.startDay = startDay;
}

public CalendarCommand<EmptyValue> createEntryCommand(){
return new CalendarCommand<>(CREATE_ENTRY + name + "/" + operatingMode + "/" + CAL_MODE + "/" + startMonth + "/" + startDay, EmptyValue.class);
@Override
public String toString() {
return name + "/" + operatingMode + "/" + CAL_MODE + "/" + startMonth + "/" + startDay;
}
}
6 changes: 3 additions & 3 deletions src/main/java/cz/smarteon/loxone/calendar/CalEntryPeriod.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import cz.smarteon.loxone.LoxoneUuid;
import cz.smarteon.loxone.user.EmptyValue;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -91,7 +90,8 @@ public CalEntryPeriod(
this.endDay = endDay;
}

public CalendarCommand<EmptyValue> createEntryCommand(){
return new CalendarCommand<>(CREATE_ENTRY + name + "/" + operatingMode + "/" + CAL_MODE + "/" + startYear + "/" + startMonth + "/" + startDay + "/" + endYear + "/" + endMonth + "/" + endDay, EmptyValue.class);
@Override
public String toString() {
return name + "/" + operatingMode + "/" + CAL_MODE + "/" + startYear + "/" + startMonth + "/" + startDay + "/" + endYear + "/" + endMonth + "/" + endDay;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import cz.smarteon.loxone.LoxoneUuid;
import cz.smarteon.loxone.user.EmptyValue;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -73,7 +72,8 @@ public CalEntryPeriodYearly(
this.endDay = endDay;
}

public CalendarCommand<EmptyValue> createEntryCommand(){
return new CalendarCommand<>(CREATE_ENTRY + name + "/" + operatingMode + "/" + CAL_MODE + "/" + startMonth + "/" + startDay + "/" + endMonth + "/" + endDay, EmptyValue.class);
@Override
public String toString() {
return name + "/" + operatingMode + "/" + CAL_MODE + "/" + startMonth + "/" + startDay + "/" + endMonth + "/" + endDay;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import cz.smarteon.loxone.LoxoneUuid;
import cz.smarteon.loxone.user.EmptyValue;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -64,7 +63,8 @@ public CalEntrySingleDay(
this.startDay = startDay;
}

public CalendarCommand<EmptyValue> createEntryCommand(){
return new CalendarCommand<>(CREATE_ENTRY + name + "/" + operatingMode + "/" + CAL_MODE + "/" + startYear + "/" + startMonth + "/" + startDay, EmptyValue.class);
@Override
public String toString() {
return name + "/" + operatingMode + "/" + CAL_MODE + "/" + startYear + "/" + startMonth + "/" + startDay;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class CalendarCommand<V extends LoxoneValue> extends LoxoneMessageCommand

private static final String GET_ENTRIES = "calendargetentries/";

private static final String COMMAND_PREFIX = "jdev/sps/";
protected static final String COMMAND_PREFIX = "jdev/sps/";

protected CalendarCommand(String operation, Class<V> valueType) {
super(requireNonNull(operation, "operation can't be null"),
Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/calendar/CalEntryDayOfWeekTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CalEntryDayOfWeekTest {
get { weekDayInMonth}.isEqualTo(1)
get { weekDay }.isEqualTo(2)
get { createEntryCommand().command }.isEqualTo("jdev/sps/calendarcreateentry/Day of week test/1/5/1/2/7")
get { updateEntryCommand(this.uuid).command }.isEqualTo("jdev/sps/calendarupdateentry/1b6f49d6-030f-9bc2-ffff504f94a03d3e/Day of week test/1/5/1/2/7")
}
}

Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/calendar/CalEntryEasterOffsetTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class CalEntryEasterOffsetTest {
get { calMode }.isEqualTo(1)
get { easterOffset }.isEqualTo(11)
get { createEntryCommand().command }.isEqualTo("jdev/sps/calendarcreateentry/Eastern offset test/1/1/11")
get { updateEntryCommand(this.uuid).command }.isEqualTo("jdev/sps/calendarupdateentry/1b6f47dd-0243-9b2c-ffff504f94a03d3e/Eastern offset test/1/1/11")
}
}

Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/calendar/CalEntryEveryYearTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CalEntryEveryYearTest {
get { startMonth }.isEqualTo(4)
get { startDay }.isEqualTo(1)
get { createEntryCommand().command }.isEqualTo("jdev/sps/calendarcreateentry/Every year test/1/0/4/1")
get { updateEntryCommand(this.uuid).command }.isEqualTo("jdev/sps/calendarupdateentry/1b6f47bd-0390-9b1e-ffff504f94a03d3e/Every year test/1/0/4/1")
}
}

Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/calendar/CalEntryPeriodTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CalEntryPeriodTest {
get { endMonth }.isEqualTo(8)
get { endDay }.isEqualTo(4)
get { createEntryCommand().command }.isEqualTo("jdev/sps/calendarcreateentry/Period test/1/3/2024/8/3/2024/8/4")
get { updateEntryCommand(this.uuid).command }.isEqualTo("jdev/sps/calendarupdateentry/1b6f480b-0393-9b59-ffff504f94a03d3e/Period test/1/3/2024/8/3/2024/8/4")
}
}

Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/calendar/CalEntryPeriodYearlyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CalEntryPeriodYearlyTest {
get { endMonth }.isEqualTo(7)
get { endDay }.isEqualTo(6)
get { createEntryCommand().command }.isEqualTo("jdev/sps/calendarcreateentry/Period every year test/1/4/7/1/7/6")
get { updateEntryCommand(this.uuid).command }.isEqualTo("jdev/sps/calendarupdateentry/1b6f49be-025c-9ba0-ffff504f94a03d3e/Period every year test/1/4/7/1/7/6")
}
}

Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/calendar/CalEntrySingleDayTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CalEntrySingleDayTest {
get { startMonth }.isEqualTo(8)
get { startDay }.isEqualTo(3)
get { createEntryCommand().command }.isEqualTo("jdev/sps/calendarcreateentry/Single day test/1/2/2024/8/3")
get { updateEntryCommand(this.uuid).command }.isEqualTo("jdev/sps/calendarupdateentry/1b6f47f0-03b0-9b3d-ffff504f94a03d3e/Single day test/1/2/2024/8/3")
}
}

Expand Down

0 comments on commit d0b1a75

Please sign in to comment.