Skip to content
This repository has been archived by the owner on Apr 30, 2023. It is now read-only.

Commit

Permalink
Updated Charts, updated hue SDK, updated time series support
Browse files Browse the repository at this point in the history
  • Loading branch information
renarj committed Nov 23, 2015
1 parent a0512b1 commit 58e640a
Show file tree
Hide file tree
Showing 40 changed files with 755 additions and 516 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface DeviceManager {

DeviceItem findDevice(String itemId);

List<DeviceItem> getDevices();
List<DeviceItem> getDevices(String controllerId);

Optional<DeviceItem> findDeviceItem(String controllerId, String pluginId, String deviceId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface ItemManager {

List<DeviceItem> findDevices(String controllerId, String pluginId);

List<DeviceItem> findDevices();
List<DeviceItem> findDevices(String controllerId);

Item findItem(String id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,33 @@
import java.util.List;
import java.util.concurrent.TimeUnit;

import static java.util.Arrays.asList;

/**
* @author renarj
*/
public interface TimeSeriesStore extends StateStore {
List<DataPoint> findDataPoints(String controllerId, String itemId, String label, long time, TimeUnit unit);

enum GROUPING {
MINUTE("60s"),
HOUR("60m"),
DAY("24h");

private String timeString;

GROUPING(String timeString) {
this.timeString = timeString;
}

public String getTimeString() {
return timeString;
}

public static GROUPING fromName(String name) {
return asList(values()).stream().filter(g -> g.name().equalsIgnoreCase(name))
.findFirst().orElseGet(() -> MINUTE);
}
}

List<DataPoint> findDataPoints(String controllerId, String itemId, String label, GROUPING grouping, long time, TimeUnit unit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface HomeDAO {

Optional<DeviceItem> findDevice(String controllerId, String pluginId, String deviceId);

List<DeviceItem> findDevices();
List<DeviceItem> findDevices(String controllerId);

<T extends VirtualItem> List<T> findVirtualItems(Class<T> type);

Expand Down
8 changes: 4 additions & 4 deletions home_hue/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
<dependencies>
<dependency>
<groupId>com.philips</groupId>
<artifactId>huesdk</artifactId>
<version>1.7</version>
<artifactId>localsdk</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>com.philips</groupId>
<artifactId>hueresource</artifactId>
<version>1.7</version>
<artifactId>resourcesdk</artifactId>
<version>1.8.1</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void onCacheUpdated(List<Integer> list, PHBridge phBridge) {
}

@Override
public void onBridgeConnected(PHBridge phBridge) {
public void onBridgeConnected(PHBridge phBridge, String s) {
LOG.info("Bridge connected: {} with user: {}", phBridge, bridgeUser);
connected.set(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Optional;

import static java.util.Arrays.asList;
import static nl.renarj.core.utilities.StringUtils.stringNotEmpty;

/**
* @author Renze de Vries
Expand Down Expand Up @@ -51,7 +52,11 @@ public void startUp() {
LOG.info("Starting MQTT Connector");

String brokers = environment.getProperty("mqtt.brokers");
asList(brokers.split(",")).forEach(this::loadBroker);
if(stringNotEmpty(brokers)) {
asList(brokers.split(",")).forEach(this::loadBroker);
} else {
LOG.info("No MQTT Brokers configured, skipping initialization");
}
}

@PreDestroy
Expand All @@ -64,15 +69,18 @@ private void loadBroker(String brokerId) {
String url = environment.getProperty("mqtt." + brokerId + ".url");
String channels = environment.getProperty("mqtt." + brokerId + ".channels");
LOG.info("Broker: {} on url: {} channels: {}", brokerId, url, channels);

MQTTBroker broker = new MQTTBroker(url);
activeBrokers.add(broker);
try {
broker.connect();

asList(channels.split(",")).forEach(c -> loadChannels(broker, brokerId, c));
} catch (HomeAutomationException e) {
throw new RuntimeHomeAutomationException("Unable to connect", e);
if(stringNotEmpty(url) && stringNotEmpty(channels)) {
MQTTBroker broker = new MQTTBroker(url);
activeBrokers.add(broker);
try {
broker.connect();

asList(channels.split(",")).forEach(c -> loadChannels(broker, brokerId, c));
} catch (HomeAutomationException e) {
throw new RuntimeHomeAutomationException("Unable to connect", e);
}
} else {
LOG.warn("Broker: {} has no url: {} or channels: {} configured", brokerId, url, channels);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.oberasoftware.home.rest;

import com.oberasoftware.home.api.managers.DeviceManager;
import com.oberasoftware.home.api.managers.ItemManager;
import com.oberasoftware.home.api.managers.StateManager;
import com.oberasoftware.home.api.model.State;
Expand Down Expand Up @@ -28,9 +27,6 @@
public class DataRestController {
private static final Logger LOG = getLogger(DataRestController.class);

@Autowired
private DeviceManager deviceManager;

@Autowired
private ItemManager itemManager;

Expand All @@ -48,6 +44,17 @@ public List<RestItemDevice> getDevices(@PathVariable String controllerId, @PathV
.collect(Collectors.toList());
}

@RequestMapping("/controllers({controllerId}/devices")
public List<RestItemDevice> getDevices(@PathVariable String controllerId) {
LOG.debug("Requested list of all devices");

List<DeviceItem> deviceItems = itemManager.findDevices(controllerId);
return deviceItems.stream()
.map(d -> new RestItemDevice(d, stateManager.getState(d.getId())))
.collect(Collectors.toList());
}


@RequestMapping("/controllers({controllerId})/plugins")
public List<PluginItem> getPlugins(@PathVariable String controllerId) {
LOG.debug("Requested a list of all plugins for controller: {}", controllerId);
Expand All @@ -58,7 +65,7 @@ public List<PluginItem> getPlugins(@PathVariable String controllerId) {
@RequestMapping("/controllers")
public List<ControllerItem> getControllers() {
LOG.debug("Requested a list of all controllers");
return itemManager.findControllers();//.stream().map(RestHomeController::new).collect(Collectors.toList());
return itemManager.findControllers();
}

@RequestMapping("/item({id})")
Expand All @@ -71,13 +78,4 @@ public State getState(@PathVariable String itemId) {
return stateManager.getState(itemId);
}

@RequestMapping("/devices")
public List<RestItemDevice> getDevices() {
LOG.debug("Requested list of all devices");

List<DeviceItem> deviceItems = itemManager.findDevices();
return deviceItems.stream()
.map(d -> new RestItemDevice(d, stateManager.getState(d.getId())))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ public class TimeSeriesRestController {
@RequestMapping("/item({itemId})/label({label})")
public List<DataPoint> findDeviceData(@PathVariable String itemId,
@PathVariable String label) {
return findDeviceData(itemId, label, DEFAULT_TIME_SCALE);
return findDeviceData(itemId, label, "minute", DEFAULT_TIME_SCALE);
}


@RequestMapping("/item({itemId})/label({label})/hours({time})")
@RequestMapping("/item({itemId})/label({label})/grouping({group})/hours({time})")
public List<DataPoint> findDeviceData(@PathVariable String itemId,
@PathVariable String label, @PathVariable long time) {
@PathVariable String label, @PathVariable String group, @PathVariable long time) {
if(timeSeriesStore != null) {
return timeSeriesStore.findDataPoints(bus.getControllerId(), itemId, label, time, TimeUnit.HOURS);
TimeSeriesStore.GROUPING grouping = TimeSeriesStore.GROUPING.fromName(group);
LOG.debug("Doing item: {} time series request for: {} hours grouped by: {}", itemId, time, grouping);

return timeSeriesStore.findDataPoints(bus.getControllerId(), itemId, label, grouping,
time, TimeUnit.HOURS);
}
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public DeviceItem findDevice(String itemId) {
}

@Override
public List<DeviceItem> getDevices() {
public List<DeviceItem> getDevices(String controllerId) {
return new ArrayList<>(deviceItems);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public Optional<DeviceItem> findDeviceItem(String controllerId, String pluginId,
}

@Override
public List<DeviceItem> getDevices() {
return homeDAO.findDevices();
public List<DeviceItem> getDevices(String controllerId) {
return homeDAO.findDevices(controllerId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public List<DeviceItem> findDevices(String controllerId, String pluginId) {
}

@Override
public List<DeviceItem> findDevices() {
return homeDAO.findDevices();
public List<DeviceItem> findDevices(String controllerId) {
return homeDAO.findDevices(controllerId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.oberasoftware.home.service;

import com.google.common.util.concurrent.Uninterruptibles;
import org.junit.Ignore;
import org.junit.Test;

import java.util.concurrent.TimeUnit;
Expand All @@ -10,7 +11,7 @@
*/
public class HomeAutomationTest {
@Test
// @Ignore
@Ignore
public void testHomeAutomation() {
new HomeAutomation().start(new String[]{});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ public Optional<DeviceItem> findDevice(String controllerId, String pluginId, Str
}

@Override
public List<DeviceItem> findDevices() {
public List<DeviceItem> findDevices(String controllerId) {
return newArrayList(findItems(DeviceItemImpl.class, new ImmutableMap.Builder<String, String>()
.put("controllerId", controllerId)
.build()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void storeAndUpdateDevice() throws JasDBException, DataStoreException {

centralDatastore.store(new DeviceItemImpl(id, "controller1", "plugin1", "device1", "updated name", new HashMap<>()));

assertThat(jasDBDAO.findDevices().size(), is(1));
assertThat(jasDBDAO.findDevices("controller1").size(), is(1));

item = jasDBDAO.findDevice("controller1", "plugin1", "device1");
assertThat(item.isPresent(), is(true));
Expand Down
Loading

0 comments on commit 58e640a

Please sign in to comment.