Skip to content

Commit fad68be

Browse files
committed
Merge pull request #5 from jrock125/new-branch
change page size from 10 to 100 to allow bridge to handle more than 10 devices from jrock125
2 parents 60c07f9 + 6e76d73 commit fad68be

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/main/java/com/armzilla/ha/dao/DeviceRepository.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.armzilla.ha.dao;
22

3+
import org.springframework.data.domain.Page;
4+
import org.springframework.data.domain.PageRequest;
5+
import org.springframework.data.domain.Pageable;
36
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
47

58
import java.util.List;
@@ -8,7 +11,7 @@
811
* Created by arm on 4/13/15.
912
*/
1013
public interface DeviceRepository extends ElasticsearchRepository<DeviceDescriptor, String> {
11-
List<DeviceDescriptor> findByDeviceType(String type);
14+
Page<DeviceDescriptor> findByDeviceType(String type, Pageable request);
1215
List<DeviceDescriptor> findAll();
1316
DeviceDescriptor findOne(String id);
1417

src/main/java/com/armzilla/ha/hue/HueMulator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.apache.http.util.EntityUtils;
1111
import org.apache.log4j.Logger;
1212
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.data.domain.Page;
14+
import org.springframework.data.domain.PageRequest;
1315
import org.springframework.http.HttpHeaders;
1416
import org.springframework.http.HttpStatus;
1517
import org.springframework.http.ResponseEntity;
@@ -45,7 +47,7 @@ public HueMulator(){
4547
@RequestMapping(value = "/{userId}/lights", method = RequestMethod.GET, produces = "application/json")
4648
public ResponseEntity<Map<String, String>> getUpnpConfiguration(@PathVariable(value = "userId") String userId, HttpServletRequest request) {
4749
log.info("hue lights list requested: " + userId + " from " + request.getRemoteAddr());
48-
List<DeviceDescriptor> deviceList = repository.findByDeviceType("switch");
50+
Page<DeviceDescriptor> deviceList = repository.findByDeviceType("switch", new PageRequest(0,100));
4951
Map<String, String> deviceResponseMap = new HashMap<>();
5052
for (DeviceDescriptor device : deviceList) {
5153
deviceResponseMap.put(device.getId(), device.getName());
@@ -56,7 +58,7 @@ public ResponseEntity<Map<String, String>> getUpnpConfiguration(@PathVariable(va
5658
@RequestMapping(value = "/{userId}", method = RequestMethod.GET, produces = "application/json")
5759
public ResponseEntity<HueApiResponse> getApi(@PathVariable(value = "userId") String userId, HttpServletRequest request) {
5860
log.info("hue api root requested: " + userId + " from " + request.getRemoteAddr());
59-
List<DeviceDescriptor> descriptorList = repository.findByDeviceType("switch");
61+
Page<DeviceDescriptor> descriptorList = repository.findByDeviceType("switch", new PageRequest(0, 100));
6062
if (descriptorList == null) {
6163
return new ResponseEntity<>(null, null, HttpStatus.NOT_FOUND);
6264
}

0 commit comments

Comments
 (0)