Compare commits
No commits in common. "master" and "deploy---2024-10-28---10-48-24" have entirely different histories.
master
...
deploy---2
@ -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) {
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user