Compare commits
No commits in common. "master" and "deploy---2024-09-12---09-31-16" have entirely different histories.
master
...
deploy---2
6
pom.xml
6
pom.xml
@ -66,12 +66,6 @@
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
@ -54,11 +54,8 @@ export class PropertyListComponent implements OnInit {
|
||||
}
|
||||
|
||||
private updateProperty(property: Property, existing: boolean): void {
|
||||
if (property.type === PropertyType.BOOLEAN) {
|
||||
this.updateProperty2(this.booleans, property, existing);
|
||||
} else if (property.type === PropertyType.SHUTTER) {
|
||||
this.updateProperty2(this.shutters, property, existing);
|
||||
}
|
||||
this.updateProperty2(this.booleans, property, existing);
|
||||
this.updateProperty2(this.shutters, property, existing);
|
||||
}
|
||||
|
||||
private updateProperty2(properties: Property[], property: Property, existing: boolean) {
|
||||
|
||||
@ -13,6 +13,8 @@ public class Config {
|
||||
|
||||
private double longitude = 6.9645334;
|
||||
|
||||
private String timezone = "Europe/Berlin";
|
||||
|
||||
private boolean insertDemoData = false;
|
||||
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package de.ph87.homeautomation.channel;
|
||||
|
||||
import de.ph87.homeautomation.property.Property;
|
||||
import de.ph87.homeautomation.shared.Helpers;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -30,11 +29,12 @@ public class ChannelReader {
|
||||
return findByChannel(channel).orElseThrow(RuntimeException::new);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Optional<Double> read(@NonNull final Property property) {
|
||||
return Optional.ofNullable(property.getReadChannel())
|
||||
.map(this::getByChannel)
|
||||
.map(owner -> owner.read(property.getReadChannel().getId()));
|
||||
public Double read(final Property property) {
|
||||
final Channel channel = property.getReadChannel();
|
||||
if (channel == null) {
|
||||
return null;
|
||||
}
|
||||
return getByChannel(channel).read(property.getReadChannel().getId());
|
||||
}
|
||||
|
||||
public ChannelDto toDtoAllowNull(final Channel channel) {
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
package de.ph87.homeautomation.knx.group;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("knx/group")
|
||||
public class KnxGroupImportController {
|
||||
|
||||
private final KnxGroupImportService knxGroupImportService;
|
||||
|
||||
@GetMapping("import")
|
||||
public void doImport() {
|
||||
knxGroupImportService.importGroups();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,6 +1,5 @@
|
||||
package de.ph87.homeautomation.knx.group;
|
||||
|
||||
import de.ph87.homeautomation.property.PropertyReader;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jsoup.Jsoup;
|
||||
@ -24,8 +23,6 @@ public class KnxGroupImportService {
|
||||
|
||||
private final KnxGroupRepository knxGroupRepository;
|
||||
|
||||
private final PropertyReader propertyReader;
|
||||
|
||||
public void importGroups() {
|
||||
try {
|
||||
execute("/usr/bin/git", "fetch", "--all");
|
||||
@ -37,18 +34,6 @@ public class KnxGroupImportService {
|
||||
knxGroupRepository.findAll().forEach(knxGroup -> knxGroup.setEts(false));
|
||||
try {
|
||||
Jsoup.parse(new File(ETS_HOME, "G"), "UTF-8").select("GA").forEach(this::importGroup);
|
||||
knxGroupRepository.findAllByEtsFalse().forEach(group -> {
|
||||
log.warn("Removing obsolete group: {}", group);
|
||||
propertyReader.findAllByReadChannel_Id(group.getId()).forEach(property -> {
|
||||
property.setReadChannel(null);
|
||||
log.warn(" - removed group as Property readChannel: {}", property);
|
||||
});
|
||||
propertyReader.findAllByWriteChannel_Id(group.getId()).forEach(property -> {
|
||||
property.setWriteChannel(null);
|
||||
log.warn(" - removed group as Property writeChannel: {}", property);
|
||||
});
|
||||
knxGroupRepository.delete(group);
|
||||
});
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to import KnxGroups: {}", e.toString());
|
||||
}
|
||||
@ -88,13 +73,7 @@ public class KnxGroupImportService {
|
||||
private void setDpt(final KnxGroup knxGroup, final String dptString) {
|
||||
final Matcher mainSub = Pattern.compile("^DPST-(?<main>\\d+)-(?<sub>\\d+)$").matcher(dptString);
|
||||
if (mainSub.matches()) {
|
||||
final int main = Integer.parseInt(mainSub.group("main"));
|
||||
if (knxGroup.getDptMain() != main) {
|
||||
knxGroup.setLastTelegram(null);
|
||||
knxGroup.setValue(null);
|
||||
knxGroup.setTimestamp(null);
|
||||
}
|
||||
knxGroup.setDptMain(main);
|
||||
knxGroup.setDptMain(Integer.parseInt(mainSub.group("main")));
|
||||
knxGroup.setDptSub(Integer.parseInt(mainSub.group("sub")));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -4,7 +4,10 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tuwien.auto.calimero.*;
|
||||
import tuwien.auto.calimero.GroupAddress;
|
||||
import tuwien.auto.calimero.KNXException;
|
||||
import tuwien.auto.calimero.KNXFormatException;
|
||||
import tuwien.auto.calimero.KNXTimeoutException;
|
||||
import tuwien.auto.calimero.datapoint.StateDP;
|
||||
import tuwien.auto.calimero.dptxlator.TranslatorTypes;
|
||||
import tuwien.auto.calimero.process.ProcessCommunicatorImpl;
|
||||
@ -71,12 +74,6 @@ public class KnxGroupLinkService {
|
||||
knxGroup.getRead().setNextTimestamp(null);
|
||||
log.debug("Successfully sent KnxGroup: {}", knxGroup);
|
||||
return true;
|
||||
} catch (KNXIllegalArgumentException e) {
|
||||
log.error("Failed to read KnxGroup {}", knxGroup);
|
||||
knxGroup.getRead().setErrorCount(knxGroup.getRead().getErrorCount() + 1);
|
||||
knxGroup.getRead().setErrorMessage(e.getMessage());
|
||||
knxGroup.getRead().setNextTimestamp(null);
|
||||
return true;
|
||||
} catch (KNXTimeoutException | KNXFormatException e) {
|
||||
log.error("Failed to read KnxGroup {}", knxGroup);
|
||||
knxGroup.getRead().setErrorCount(knxGroup.getRead().getErrorCount() + 1);
|
||||
|
||||
@ -1,16 +1,18 @@
|
||||
package de.ph87.homeautomation.knx.group;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.ListCrudRepository;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface KnxGroupRepository extends ListCrudRepository<KnxGroup, Long>, JpaSpecificationExecutor<KnxGroup> {
|
||||
public interface KnxGroupRepository extends CrudRepository<KnxGroup, Long>, JpaSpecificationExecutor<KnxGroup> {
|
||||
|
||||
Optional<KnxGroup> findByAddressRaw(int rawAddress);
|
||||
|
||||
List<KnxGroup> findAll();
|
||||
|
||||
Optional<KnxGroup> findFirstBySend_NextTimestampNotNullOrderBySend_NextTimestampAsc();
|
||||
|
||||
Optional<KnxGroup> findFirstByRead_NextTimestampLessThanEqualOrderByRead_NextTimestampAsc(ZonedDateTime timestamp);
|
||||
@ -19,6 +21,4 @@ public interface KnxGroupRepository extends ListCrudRepository<KnxGroup, Long>,
|
||||
|
||||
List<KnxGroup> findAllByNameContainsIgnoreCaseOrAddressStrContainsIgnoreCase(String name, String addressStr);
|
||||
|
||||
List<KnxGroup> findAllByEtsFalse();
|
||||
|
||||
}
|
||||
|
||||
@ -44,11 +44,6 @@ public class PropertyController implements ISearchController {
|
||||
return propertyWriter.set(id, Property::setSlug, value == null || value.isEmpty() ? null : value);
|
||||
}
|
||||
|
||||
@GetMapping("get/{id}/value")
|
||||
public Double getValue(@PathVariable final long id) {
|
||||
return channelReader.read(propertyReader.getById(id)).orElse(null);
|
||||
}
|
||||
|
||||
@PostMapping("set/{id}/value")
|
||||
public PropertyDto setValue(@PathVariable final long id, @RequestBody final double value) {
|
||||
return propertyWriter.set(id, propertyWriter::writeToChannel, value);
|
||||
@ -71,10 +66,18 @@ public class PropertyController implements ISearchController {
|
||||
|
||||
@PostMapping("toggle/{id}")
|
||||
public PropertyDto setValue(@PathVariable final long id) {
|
||||
final boolean oldState = channelReader.read(propertyReader.getById(id)).map(v -> v > 0.0).orElse(false);
|
||||
final boolean oldState = getOldStateBoolean(id, false);
|
||||
return propertyWriter.set(id, propertyWriter::writeToChannel, oldState ? 0.0 : 1.0);
|
||||
}
|
||||
|
||||
private boolean getOldStateBoolean(final long id, final boolean orElse) {
|
||||
final Double oldValue = channelReader.read(propertyReader.getById(id));
|
||||
if (oldValue == null || oldValue.isNaN()) {
|
||||
return orElse;
|
||||
}
|
||||
return oldValue > 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("searchById/{id}")
|
||||
public SearchResult searchById(@PathVariable final long id) {
|
||||
|
||||
@ -23,10 +23,6 @@ public class PropertyReader {
|
||||
return propertyRepository.findAllByReadChannel_Id(readChannelId);
|
||||
}
|
||||
|
||||
public List<Property> findAllByWriteChannel_Id(final long writeChannelId) {
|
||||
return propertyRepository.findAllByWriteChannel_Id(writeChannelId);
|
||||
}
|
||||
|
||||
public List<PropertyDto> search(final String term) {
|
||||
return RepositorySearchHelper.search(term, propertyRepository, "title", propertyMapper::toDto);
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ public interface PropertyRepository extends JpaRepository<Property, Long>, JpaSp
|
||||
|
||||
List<Property> findAllByReadChannel_Id(long readChannelId);
|
||||
|
||||
List<Property> findAllByWriteChannel_Id(final long writeChannelId);
|
||||
List<Property> findAllByTitleLikeIgnoreCase(final String like);
|
||||
|
||||
boolean existsByTitle(String title);
|
||||
|
||||
|
||||
@ -11,8 +11,6 @@ import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Comparator;
|
||||
import java.util.Optional;
|
||||
@ -57,12 +55,12 @@ public class ScheduleCalculator {
|
||||
entry.setNextClearTimestamp(null);
|
||||
return;
|
||||
}
|
||||
LocalDate day = now.toLocalDate();
|
||||
ZonedDateTime next = calculateEntryForDay(entry, day);
|
||||
ZonedDateTime midnight = now.withHour(0).withMinute(0).withSecond(0).withNano(0);
|
||||
ZonedDateTime next = calculateEntryForDay(entry, midnight);
|
||||
while (next != null && (!next.isAfter(now) || !isAfterLast(entry, next) || !isWeekdayEnabled(entry, next))) {
|
||||
log.debug(" -- skipping: next={}", next);
|
||||
day = day.plusDays(1);
|
||||
next = calculateEntryForDay(entry, day);
|
||||
midnight = midnight.plusDays(1);
|
||||
next = calculateEntryForDay(entry, midnight);
|
||||
}
|
||||
log.debug(" => {}", next);
|
||||
entry.setNextClearTimestamp(next);
|
||||
@ -72,14 +70,14 @@ public class ScheduleCalculator {
|
||||
return entry.getLastClearTimestamp() == null || next.isAfter(entry.getLastClearTimestamp());
|
||||
}
|
||||
|
||||
private ZonedDateTime calculateEntryForDay(final ScheduleEntry entry, final LocalDate day) {
|
||||
private ZonedDateTime calculateEntryForDay(final ScheduleEntry entry, final ZonedDateTime midnight) {
|
||||
switch (entry.getType()) {
|
||||
case TIME:
|
||||
return day.atStartOfDay().atZone(ZoneId.systemDefault()).withHour(entry.getHour()).withMinute(entry.getMinute()).withSecond(entry.getSecond());
|
||||
return midnight.withHour(entry.getHour()).withMinute(entry.getMinute()).withSecond(entry.getSecond());
|
||||
case SUNRISE:
|
||||
case SUNSET:
|
||||
final boolean sunrise = entry.getType() == ScheduleEntryType.SUNRISE;
|
||||
return astroCalculator.forDay(day, sunrise, entry.getZenith()).withLaterOffsetAtOverlap();
|
||||
return astroCalculator.forDay(midnight, sunrise, entry.getZenith());
|
||||
default:
|
||||
log.error("AstroEvent not implemented: {}", entry.getType());
|
||||
break;
|
||||
|
||||
@ -8,12 +8,10 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@ -21,15 +19,25 @@ public class AstroCalculator {
|
||||
|
||||
private final Config config;
|
||||
|
||||
public ZonedDateTime forDay(final LocalDate day, final boolean sunrise, final double zenith) {
|
||||
public ZonedDateTime next(final ZonedDateTime now, final boolean sunrise, final double zenith) {
|
||||
ZonedDateTime day = now.truncatedTo(ChronoUnit.DAYS);
|
||||
ZonedDateTime next;
|
||||
do {
|
||||
next = forDay(day, sunrise, zenith);
|
||||
day = day.plusDays(1);
|
||||
} while (next != null && !next.isAfter(now));
|
||||
return next;
|
||||
}
|
||||
|
||||
public ZonedDateTime forDay(final ZonedDateTime midnight, final boolean sunrise, final double zenith) {
|
||||
final Location location = new Location(config.getLatitude(), config.getLongitude());
|
||||
final SolarEventCalculator calculator = new SolarEventCalculator(location, TimeZone.getTimeZone("UTC"));
|
||||
final Calendar calendar = GregorianCalendar.from(day.atStartOfDay(ZoneId.of("UTC")));
|
||||
final SolarEventCalculator calculator = new SolarEventCalculator(location, config.getTimezone());
|
||||
final Calendar calendar = GregorianCalendar.from(midnight);
|
||||
final Calendar nextCalendar = forDay(calculator, sunrise, new Zenith(zenith), calendar);
|
||||
if (nextCalendar == null) {
|
||||
return null;
|
||||
}
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(nextCalendar.getTimeInMillis()), ZoneId.systemDefault());
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(nextCalendar.getTimeInMillis()), midnight.getZone());
|
||||
}
|
||||
|
||||
private Calendar forDay(final SolarEventCalculator calculator, final boolean sunrise, final Zenith solarZenith, final Calendar calendar) {
|
||||
|
||||
@ -2,10 +2,12 @@ package de.ph87.homeautomation.web;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
|
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
|
||||
|
||||
@CrossOrigin
|
||||
@Configuration
|
||||
@EnableWebSocketMessageBroker
|
||||
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
|
||||
|
||||
@ -1,70 +0,0 @@
|
||||
package de.ph87.homeautomation.schedule;
|
||||
|
||||
import de.ph87.homeautomation.Config;
|
||||
import de.ph87.homeautomation.schedule.astro.AstroCalculator;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@Slf4j
|
||||
class ScheduleCalculatorDaylightSavingTimeTransitionTest {
|
||||
|
||||
private static final ZonedDateTime DAY_OF_DST_SET_BACK = ZonedDateTime.of(2024, 10, 27, 0, 0, 0, 0, ZoneId.of("Europe/Berlin"));
|
||||
|
||||
private static final AstroCalculator astroCalculator = new AstroCalculator(new Config());
|
||||
|
||||
@Test
|
||||
void withHour() {
|
||||
final ZonedDateTime morning = DAY_OF_DST_SET_BACK.withHour(6);
|
||||
assertEquals(6, morning.getHour());
|
||||
assertEquals(0, morning.getMinute());
|
||||
assertEquals(0, morning.getSecond());
|
||||
assertEquals(0, morning.getNano());
|
||||
assertEquals(3600, morning.getOffset().getTotalSeconds());
|
||||
}
|
||||
|
||||
@Test
|
||||
void sunrise_dstSetBack() {
|
||||
final ZonedDateTime morning = astroCalculator.forDay(DAY_OF_DST_SET_BACK.toLocalDate(), true, 90);
|
||||
assertEquals(7, morning.getHour());
|
||||
assertEquals(19, morning.getMinute());
|
||||
assertEquals(0, morning.getSecond());
|
||||
assertEquals(0, morning.getNano());
|
||||
assertEquals(3600, morning.getOffset().getTotalSeconds());
|
||||
}
|
||||
|
||||
@Test
|
||||
void sunset_dstSetBack() {
|
||||
final ZonedDateTime morning = astroCalculator.forDay(DAY_OF_DST_SET_BACK.toLocalDate(), false, 90);
|
||||
assertEquals(17, morning.getHour());
|
||||
assertEquals(13, morning.getMinute());
|
||||
assertEquals(0, morning.getSecond());
|
||||
assertEquals(0, morning.getNano());
|
||||
assertEquals(3600, morning.getOffset().getTotalSeconds());
|
||||
}
|
||||
|
||||
@Test
|
||||
void sunrise_noDstChange() {
|
||||
final ZonedDateTime morning = astroCalculator.forDay(DAY_OF_DST_SET_BACK.minusDays(1).toLocalDate(), true, 90);
|
||||
assertEquals(8, morning.getHour());
|
||||
assertEquals(17, morning.getMinute());
|
||||
assertEquals(0, morning.getSecond());
|
||||
assertEquals(0, morning.getNano());
|
||||
assertEquals(7200, morning.getOffset().getTotalSeconds());
|
||||
}
|
||||
|
||||
@Test
|
||||
void sunset_noDstChange() {
|
||||
final ZonedDateTime morning = astroCalculator.forDay(DAY_OF_DST_SET_BACK.minusDays(1).toLocalDate(), false, 90);
|
||||
assertEquals(18, morning.getHour());
|
||||
assertEquals(14, morning.getMinute());
|
||||
assertEquals(0, morning.getSecond());
|
||||
assertEquals(0, morning.getNano());
|
||||
assertEquals(7200, morning.getOffset().getTotalSeconds());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user