updating (and deleting) KnxGroup from ETS files
This commit is contained in:
parent
bad017e1dd
commit
2986238dc8
@ -1,5 +1,6 @@
|
||||
package de.ph87.homeautomation.knx.group;
|
||||
|
||||
import de.ph87.homeautomation.property.PropertyReader;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jsoup.Jsoup;
|
||||
@ -23,6 +24,8 @@ public class KnxGroupImportService {
|
||||
|
||||
private final KnxGroupRepository knxGroupRepository;
|
||||
|
||||
private final PropertyReader propertyReader;
|
||||
|
||||
public void importGroups() {
|
||||
try {
|
||||
execute("/usr/bin/git", "fetch", "--all");
|
||||
@ -34,6 +37,18 @@ 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());
|
||||
}
|
||||
@ -73,7 +88,13 @@ 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()) {
|
||||
knxGroup.setDptMain(Integer.parseInt(mainSub.group("main")));
|
||||
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.setDptSub(Integer.parseInt(mainSub.group("sub")));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1,18 +1,16 @@
|
||||
package de.ph87.homeautomation.knx.group;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.ListCrudRepository;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface KnxGroupRepository extends CrudRepository<KnxGroup, Long>, JpaSpecificationExecutor<KnxGroup> {
|
||||
public interface KnxGroupRepository extends ListCrudRepository<KnxGroup, Long>, JpaSpecificationExecutor<KnxGroup> {
|
||||
|
||||
Optional<KnxGroup> findByAddressRaw(int rawAddress);
|
||||
|
||||
List<KnxGroup> findAll();
|
||||
|
||||
Optional<KnxGroup> findFirstBySend_NextTimestampNotNullOrderBySend_NextTimestampAsc();
|
||||
|
||||
Optional<KnxGroup> findFirstByRead_NextTimestampLessThanEqualOrderByRead_NextTimestampAsc(ZonedDateTime timestamp);
|
||||
@ -21,4 +19,6 @@ public interface KnxGroupRepository extends CrudRepository<KnxGroup, Long>, JpaS
|
||||
|
||||
List<KnxGroup> findAllByNameContainsIgnoreCaseOrAddressStrContainsIgnoreCase(String name, String addressStr);
|
||||
|
||||
List<KnxGroup> findAllByEtsFalse();
|
||||
|
||||
}
|
||||
|
||||
@ -23,6 +23,10 @@ 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> findAllByTitleLikeIgnoreCase(final String like);
|
||||
List<Property> findAllByWriteChannel_Id(final long writeChannelId);
|
||||
|
||||
boolean existsByTitle(String title);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user