diff --git a/pom.xml b/pom.xml index b756c66..d60d566 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 3.5.1f + 3.5.1g jar HA Bridge diff --git a/src/main/java/com/bwssystems/hass/Attributes.java b/src/main/java/com/bwssystems/hass/Attributes.java deleted file mode 100644 index 3848854..0000000 --- a/src/main/java/com/bwssystems/hass/Attributes.java +++ /dev/null @@ -1,303 +0,0 @@ -package com.bwssystems.hass; -import java.util.List; -import com.google.gson.annotations.Expose; -import com.google.gson.annotations.SerializedName; - -public class Attributes { - -@SerializedName("Vera Device Id") -@Expose -private Integer veraDeviceId; -@SerializedName("friendly_name") -@Expose -private String friendlyName; -@SerializedName("supported_features") -@Expose -private Integer supportedFeatures; -@SerializedName("attribution") -@Expose -private String attribution; -@SerializedName("entity_picture") -@Expose -private String entityPicture; -@SerializedName("azimuth") -@Expose -private Double azimuth; -@SerializedName("elevation") -@Expose -private Double elevation; -@SerializedName("next_rising") -@Expose -private String nextRising; -@SerializedName("next_setting") -@Expose -private String nextSetting; -@SerializedName("current_power_mwh") -@Expose -private Integer currentPowerMwh; -@SerializedName("auto") -@Expose -private Boolean auto; -@SerializedName("entity_id") -@Expose -private List entityId = null; -@SerializedName("hidden") -@Expose -private Boolean hidden; -@SerializedName("order") -@Expose -private Integer order; - -/** -* -* @return -* The veraDeviceId -*/ -public Integer getVeraDeviceId() { -return veraDeviceId; -} - -/** -* -* @param veraDeviceId -* The Vera Device Id -*/ -public void setVeraDeviceId(Integer veraDeviceId) { -this.veraDeviceId = veraDeviceId; -} - -/** -* -* @return -* The friendlyName -*/ -public String getFriendlyName() { -return friendlyName; -} - -/** -* -* @param friendlyName -* The friendly_name -*/ -public void setFriendlyName(String friendlyName) { -this.friendlyName = friendlyName; -} - -/** -* -* @return -* The supportedFeatures -*/ -public Integer getSupportedFeatures() { -return supportedFeatures; -} - -/** -* -* @param supportedFeatures -* The supported_features -*/ -public void setSupportedFeatures(Integer supportedFeatures) { -this.supportedFeatures = supportedFeatures; -} - -/** -* -* @return -* The attribution -*/ -public String getAttribution() { -return attribution; -} - -/** -* -* @param attribution -* The attribution -*/ -public void setAttribution(String attribution) { -this.attribution = attribution; -} - -/** -* -* @return -* The entityPicture -*/ -public String getEntityPicture() { -return entityPicture; -} - -/** -* -* @param entityPicture -* The entity_picture -*/ -public void setEntityPicture(String entityPicture) { -this.entityPicture = entityPicture; -} - -/** -* -* @return -* The azimuth -*/ -public Double getAzimuth() { -return azimuth; -} - -/** -* -* @param azimuth -* The azimuth -*/ -public void setAzimuth(Double azimuth) { -this.azimuth = azimuth; -} - -/** -* -* @return -* The elevation -*/ -public Double getElevation() { -return elevation; -} - -/** -* -* @param elevation -* The elevation -*/ -public void setElevation(Double elevation) { -this.elevation = elevation; -} - -/** -* -* @return -* The nextRising -*/ -public String getNextRising() { -return nextRising; -} - -/** -* -* @param nextRising -* The next_rising -*/ -public void setNextRising(String nextRising) { -this.nextRising = nextRising; -} - -/** -* -* @return -* The nextSetting -*/ -public String getNextSetting() { -return nextSetting; -} - -/** -* -* @param nextSetting -* The next_setting -*/ -public void setNextSetting(String nextSetting) { -this.nextSetting = nextSetting; -} - -/** -* -* @return -* The currentPowerMwh -*/ -public Integer getCurrentPowerMwh() { -return currentPowerMwh; -} - -/** -* -* @param currentPowerMwh -* The current_power_mwh -*/ -public void setCurrentPowerMwh(Integer currentPowerMwh) { -this.currentPowerMwh = currentPowerMwh; -} - -/** -* -* @return -* The auto -*/ -public Boolean getAuto() { -return auto; -} - -/** -* -* @param auto -* The auto -*/ -public void setAuto(Boolean auto) { -this.auto = auto; -} - -/** -* -* @return -* The entityId -*/ -public List getEntityId() { -return entityId; -} - -/** -* -* @param entityId -* The entity_id -*/ -public void setEntityId(List entityId) { -this.entityId = entityId; -} - -/** -* -* @return -* The hidden -*/ -public Boolean getHidden() { -return hidden; -} - -/** -* -* @param hidden -* The hidden -*/ -public void setHidden(Boolean hidden) { -this.hidden = hidden; -} - -/** -* -* @return -* The order -*/ -public Integer getOrder() { -return order; -} - -/** -* -* @param order -* The order -*/ -public void setOrder(Integer order) { -this.order = order; -} - -} diff --git a/src/main/java/com/bwssystems/hass/FieldElement.java b/src/main/java/com/bwssystems/hass/FieldElement.java deleted file mode 100644 index 0d94615..0000000 --- a/src/main/java/com/bwssystems/hass/FieldElement.java +++ /dev/null @@ -1,52 +0,0 @@ - -package com.bwssystems.hass; - -import com.google.gson.annotations.Expose; -import com.google.gson.annotations.SerializedName; - -public class FieldElement { - - @SerializedName("description") - @Expose - private String description; - @SerializedName("example") - @Expose - private String example; - - /** - * - * @return - * The description - */ - public String getDescription() { - return description; - } - - /** - * - * @param description - * The description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * - * @return - * The example - */ - public String getExample() { - return example; - } - - /** - * - * @param example - * The example - */ - public void setExample(String example) { - this.example = example; - } - -} diff --git a/src/main/java/com/bwssystems/hass/HassHome.java b/src/main/java/com/bwssystems/hass/HassHome.java new file mode 100644 index 0000000..6e79533 --- /dev/null +++ b/src/main/java/com/bwssystems/hass/HassHome.java @@ -0,0 +1,9 @@ +package com.bwssystems.hass; + +public class HassHome { + + public HassHome() { + // TODO Auto-generated constructor stub + } + +} diff --git a/src/main/java/com/bwssystems/hass/State.java b/src/main/java/com/bwssystems/hass/State.java index 7f8544b..b26fd5d 100644 --- a/src/main/java/com/bwssystems/hass/State.java +++ b/src/main/java/com/bwssystems/hass/State.java @@ -1,5 +1,8 @@ package com.bwssystems.hass; +import java.util.Map; + +import com.google.gson.JsonElement; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; @@ -7,7 +10,7 @@ public class State { @SerializedName("attributes") @Expose -private Attributes attributes; +private Map attributes; @SerializedName("entity_id") @Expose private String entityId; @@ -26,7 +29,7 @@ private String state; * @return * The attributes */ -public Attributes getAttributes() { +public Map getAttributes() { return attributes; } @@ -35,7 +38,7 @@ return attributes; * @param attributes * The attributes */ -public void setAttributes(Attributes attributes) { +public void setAttributes(Map attributes) { this.attributes = attributes; } diff --git a/src/main/java/com/bwssystems/hass/TestService.java b/src/test/java/com/bwssystems/hass/test/ServiceDataConstructor.java similarity index 86% rename from src/main/java/com/bwssystems/hass/TestService.java rename to src/test/java/com/bwssystems/hass/test/ServiceDataConstructor.java index 635f916..e11aa31 100644 --- a/src/main/java/com/bwssystems/hass/TestService.java +++ b/src/test/java/com/bwssystems/hass/test/ServiceDataConstructor.java @@ -1,32 +1,47 @@ -package com.bwssystems.hass; +package com.bwssystems.hass.test; import java.util.Map; import java.util.Map.Entry; +import com.bwssystems.hass.Field; +import com.bwssystems.hass.FieldDeserializer; +import com.bwssystems.hass.Service; +import com.bwssystems.hass.ServiceDeserializer; +import com.bwssystems.hass.ServiceElement; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; -public class TestService { +public class ServiceDataConstructor { public final static String TestData = "[{\"domain\": \"homeassistant\", \"services\": {\"reload_core_config\": {\"description\": \"\", \"fields\": {}}, \"restart\": {\"description\": \"\", \"fields\": {}}, \"stop\": {\"description\": \"\", \"fields\": {}}, \"toggle\": {\"description\": \"\", \"fields\": {}}, \"turn_off\": {\"description\": \"\", \"fields\": {}}, \"turn_on\": {\"description\": \"\", \"fields\": {}}}}, {\"domain\": \"lock\", \"services\": {\"lock\": {\"description\": \"Lock all or specified locks\", \"fields\": {\"code\": {\"description\": \"An optional code to lock the lock with\", \"example\": 1234}, \"entity_id\": {\"description\": \"Name of lock to lock\", \"example\": \"lock.front_door\"}}}, \"unlock\": {\"description\": \"Unlock all or specified locks\", \"fields\": {\"code\": {\"description\": \"An optional code to unlock the lock with\", \"example\": 1234}, \"entity_id\": {\"description\": \"Name of lock to unlock\", \"example\": \"lock.front_door\"}}}}}, {\"domain\": \"light\", \"services\": {\"toggle\": {\"description\": \"Toggles a light\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of entities to toggle\", \"example\": \"light.kitchen\"}, \"transition\": {\"description\": \"Duration in seconds it takes to get to next state\", \"example\": 60}}}, \"turn_off\": {\"description\": \"Turn a light off\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of entities to turn off\", \"example\": \"light.kitchen\"}, \"flash\": {\"description\": \"If the light should flash\", \"values\": [\"short\", \"long\"]}, \"transition\": {\"description\": \"Duration in seconds it takes to get to next state\", \"example\": 60}}}, \"turn_on\": {\"description\": \"Turn a light on\", \"fields\": {\"brightness\": {\"description\": \"Number between 0..255 indicating brightness\", \"example\": 120}, \"color_name\": {\"description\": \"A human readable color name\", \"example\": \"red\"}, \"color_temp\": {\"description\": \"Color temperature for the light in mireds (154-500)\", \"example\": \"250\"}, \"effect\": {\"description\": \"Light effect\", \"values\": [\"colorloop\", \"random\"]}, \"entity_id\": {\"description\": \"Name(s) of entities to turn on\", \"example\": \"light.kitchen\"}, \"flash\": {\"description\": \"If the light should flash\", \"values\": [\"short\", \"long\"]}, \"profile\": {\"description\": \"Name of a light profile to use\", \"example\": \"relax\"}, \"rgb_color\": {\"description\": \"Color for the light in RGB-format\", \"example\": \"[255, 100, 100]\"}, \"transition\": {\"description\": \"Duration in seconds it takes to get to next state\", \"example\": 60}, \"white_value\": {\"description\": \"Number between 0..255 indicating level of white\", \"example\": \"250\"}, \"xy_color\": {\"description\": \"Color for the light in XY-format\", \"example\": \"[0.52, 0.43]\"}}}}}, {\"domain\": \"switch\", \"services\": {\"toggle\": {\"description\": \"Toggles a switch state\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of entities to toggle\", \"example\": \"switch.living_room\"}}}, \"turn_off\": {\"description\": \"Turn a switch off\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of entities to turn off\", \"example\": \"switch.living_room\"}}}, \"turn_on\": {\"description\": \"Turn a switch on\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of entities to turn on\", \"example\": \"switch.living_room\"}}}}}, {\"domain\": \"conversation\", \"services\": {\"process\": {\"description\": \"\", \"fields\": {}}}}, {\"domain\": \"climate\", \"services\": {\"set_aux_heat\": {\"description\": \"Turn auxillary heater on/off for climate device\", \"fields\": {\"aux_heat\": {\"description\": \"New value of axillary heater\", \"example\": true}, \"entity_id\": {\"description\": \"Name(s) of entities to change\", \"example\": \"climate.kitchen\"}}}, \"set_away_mode\": {\"description\": \"Turn away mode on/off for climate device\", \"fields\": {\"away_mode\": {\"description\": \"New value of away mode\", \"example\": true}, \"entity_id\": {\"description\": \"Name(s) of entities to change\", \"example\": \"climate.kitchen\"}}}, \"set_fan_mode\": {\"description\": \"Set fan operation for climate device\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of entities to change\", \"example\": \"climate.nest\"}, \"fan\": {\"description\": \"New value of fan mode\", \"example\": \"On Low\"}}}, \"set_humidity\": {\"description\": \"Set target humidity of climate device\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of entities to change\", \"example\": \"climate.kitchen\"}, \"humidity\": {\"description\": \"New target humidity for climate device\", \"example\": 60}}}, \"set_operation_mode\": {\"description\": \"Set operation mode for climate device\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of entities to change\", \"example\": \"climet.nest\"}, \"operation_mode\": {\"description\": \"New value of operation mode\", \"example\": \"Heat\"}}}, \"set_swing_mode\": {\"description\": \"Set swing operation for climate device\", \"fields\": {\"description\": \"New value of swing mode\", \"entity_id\": {\"description\": \"Name(s) of entities to change\", \"example\": \".nest\"}, \"example\": 1, \"swing_mode\": null}}, \"set_temperature\": {\"description\": \"Set target temperature of climate device\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of entities to change\", \"example\": \"climate.kitchen\"}, \"operation_mode\": {\"description\": \"Operation mode to set temperature to. This defaults to current_operation mode if not set, or set incorrectly.\", \"example\": \"Heat\"}, \"target_temp_high\": {\"description\": \"New target high tempereature for hvac\", \"example\": 26}, \"target_temp_low\": {\"description\": \"New target low temperature for hvac\", \"example\": 20}, \"temperature\": {\"description\": \"New target temperature for hvac\", \"example\": 25}}}}}, {\"domain\": \"cover\", \"services\": {\"close_cover\": {\"description\": \"Close all or specified cover\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of cover(s) to close\", \"example\": \"cover.living_room\"}}}, \"close_cover_tilt\": {\"description\": \"Close all or specified cover tilt\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of cover(s) to close tilt\", \"example\": \"cover.living_room\"}}}, \"open_cover\": {\"description\": \"Open all or specified cover\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of cover(s) to open\", \"example\": \"cover.living_room\"}}}, \"open_cover_tilt\": {\"description\": \"Open all or specified cover tilt\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of cover(s) tilt to open\", \"example\": \"cover.living_room\"}}}, \"set_cover_position\": {\"description\": \"Move to specific position all or specified cover\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of cover(s) to set cover position\", \"example\": \"cover.living_room\"}, \"position\": {\"description\": \"Position of the cover (0 to 100)\", \"example\": 30}}}, \"set_cover_tilt_position\": {\"description\": \"Move to specific position all or specified cover tilt\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of cover(s) to set cover tilt position\", \"example\": \"cover.living_room\"}, \"position\": {\"description\": \"Position of the cover (0 to 100)\", \"example\": 30}}}, \"stop_cover\": {\"description\": \"Stop all or specified cover\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of cover(s) to stop\", \"example\": \"cover.living_room\"}}}, \"stop_cover_tilt\": {\"description\": \"Stop all or specified cover\", \"fields\": {\"entity_id\": {\"description\": \"Name(s) of cover(s) to stop\", \"example\": \"cover.living_room\"}}}}}, {\"domain\": \"persistent_notification\", \"services\": {\"create\": {\"description\": \"Show a notification in the frontend\", \"fields\": {\"message\": {\"description\": \"Message body of the notification. [Templates accepted]\", \"example\": \"Please check your configuration.yaml.\"}, \"notification_id\": {\"description\": \"Target ID of the notification, will replace a notification with the same Id. [Optional]\", \"example\": 1234}, \"title\": {\"description\": \"Optional title for your notification. [Optional, Templates accepted]\", \"example\": \"Test notification\"}}}}}, {\"domain\": \"logbook\", \"services\": {\"log\": {\"description\": \"\", \"fields\": {}}}}]"; public static void main(String[] args){ - Gson aGson; - aGson = new GsonBuilder() - .registerTypeAdapter(Service.class, new ServiceDeserializer()) - .registerTypeHierarchyAdapter(Field.class, new FieldDeserializer()) - .create(); - - Service[] aService = aGson.fromJson(TestData, Service[].class); - for(int i = 0; i < aService.length; i++) { - System.out.println(aService[i].getDomain()); - Map services = aService[i].getServices(); - for(Entry theServiceEntry:services.entrySet()) { - System.out.println(" " + theServiceEntry.getKey()); - Field theField = theServiceEntry.getValue().getFields(); - for(Entry theFieldEntry:theField.getFields().entrySet()) - System.out.println(" " + theFieldEntry.getKey()); - } - } + ServiceDataConstructor aTestService = new ServiceDataConstructor(); + if(aTestService.validateStructure()) + System.out.println("Test Successful"); } + public Boolean validateStructure() { + Gson aGson; + try { + aGson = new GsonBuilder() + .registerTypeAdapter(Service.class, new ServiceDeserializer()) + .registerTypeHierarchyAdapter(Field.class, new FieldDeserializer()) + .create(); + + Service[] aService = aGson.fromJson(TestData, Service[].class); + for(int i = 0; i < aService.length; i++) { + System.out.println(aService[i].getDomain()); + Map services = aService[i].getServices(); + for(Entry theServiceEntry:services.entrySet()) { + System.out.println(" " + theServiceEntry.getKey()); + Field theField = theServiceEntry.getValue().getFields(); + for(Entry theFieldEntry:theField.getFields().entrySet()) + System.out.println(" " + theFieldEntry.getKey()); + } + } + } catch (Exception e) { + return false; + } + return true; + } } diff --git a/src/test/java/com/bwssystems/hass/test/ServiceStructureTestCase.java b/src/test/java/com/bwssystems/hass/test/ServiceStructureTestCase.java new file mode 100644 index 0000000..6e08aca --- /dev/null +++ b/src/test/java/com/bwssystems/hass/test/ServiceStructureTestCase.java @@ -0,0 +1,14 @@ +package com.bwssystems.hass.test; + +import org.junit.Assert; +import org.junit.Test; + +public class ServiceStructureTestCase { + + @Test + public void testValidateStructure() { + ServiceDataConstructor aTestService = new ServiceDataConstructor(); + Assert.assertEquals(aTestService.validateStructure(), true); + } + +} diff --git a/src/test/java/com/bwssystems/hass/test/StateDataConstructor.java b/src/test/java/com/bwssystems/hass/test/StateDataConstructor.java new file mode 100644 index 0000000..3ed9f22 --- /dev/null +++ b/src/test/java/com/bwssystems/hass/test/StateDataConstructor.java @@ -0,0 +1,42 @@ +package com.bwssystems.hass.test; + +import java.util.Map.Entry; + +import com.bwssystems.hass.State; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; + +public class StateDataConstructor { + public final static String TestData = "[{\"attributes\": {\"Vera Device Id\": 43, \"friendly_name\": \"Family Ceiling\", \"supported_features\": 1}, \"entity_id\": \"light.family_ceiling\", \"last_changed\": \"2016-12-09T15:29:33.069914+00:00\", \"last_updated\": \"2016-12-09T15:29:33.069914+00:00\", \"state\": \"off\"}, {\"attributes\": {\"Vera Device Id\": 46, \"friendly_name\": \"Living Room\", \"supported_features\": 1}, \"entity_id\": \"light.living_room\", \"last_changed\": \"2016-12-09T15:29:33.038648+00:00\", \"last_updated\": \"2016-12-09T15:29:33.038648+00:00\", \"state\": \"off\"}, {\"attributes\": {\"Vera Device Id\": 59, \"friendly_name\": \"Test Light on CM15 (RF) P1\"}, \"entity_id\": \"switch.test_light_on_cm15_rf_p1\", \"last_changed\": \"2016-12-09T15:29:33.205020+00:00\", \"last_updated\": \"2016-12-09T15:29:33.205020+00:00\", \"state\": \"off\"}, {\"attributes\": {\"Vera Device Id\": 60, \"friendly_name\": \"Test Light on CM15 (PL) N1\", \"supported_features\": 1}, \"entity_id\": \"light.test_light_on_cm15_pl_n1\", \"last_changed\": \"2016-12-09T15:29:33.062192+00:00\", \"last_updated\": \"2016-12-09T15:29:33.062192+00:00\", \"state\": \"off\"}, {\"attributes\": {\"Vera Device Id\": 55, \"friendly_name\": \"Topiary Tree\"}, \"entity_id\": \"switch.topiary_tree\", \"last_changed\": \"2016-12-09T15:29:33.192865+00:00\", \"last_updated\": \"2016-12-09T15:29:33.192865+00:00\", \"state\": \"off\"}, {\"attributes\": {\"Vera Device Id\": 45, \"friendly_name\": \"House B\"}, \"entity_id\": \"switch.house_b\", \"last_changed\": \"2016-12-09T15:29:33.185026+00:00\", \"last_updated\": \"2016-12-09T15:29:33.185026+00:00\", \"state\": \"off\"}, {\"attributes\": {\"attribution\": \"Weather forecast from yr.no, delivered by the Norwegian Meteorological Institute and the NRK.\", \"entity_picture\": \"//api.met.no/weatherapi/weathericon/1.1/?symbol=3;content_type=image/png\", \"friendly_name\": \"yr Symbol\"}, \"entity_id\": \"sensor.yr_symbol\", \"last_changed\": \"2016-12-09T15:29:32.774160+00:00\", \"last_updated\": \"2016-12-09T15:29:32.774160+00:00\", \"state\": \"3\"}, {\"attributes\": {\"azimuth\": 156.57, \"elevation\": 21.62, \"friendly_name\": \"Sun\", \"next_rising\": \"2016-12-10T13:08:09+00:00\", \"next_setting\": \"2016-12-09T22:19:14+00:00\"}, \"entity_id\": \"sun.sun\", \"last_changed\": \"2016-12-09T15:29:30.986518+00:00\", \"last_updated\": \"2016-12-09T16:08:30.700707+00:00\", \"state\": \"above_horizon\"}, {\"attributes\": {\"Vera Device Id\": 36, \"friendly_name\": \"Test Light on a CM11\", \"supported_features\": 1}, \"entity_id\": \"light.test_light_on_a_cm11\", \"last_changed\": \"2016-12-09T15:29:33.085475+00:00\", \"last_updated\": \"2016-12-09T15:29:33.085475+00:00\", \"state\": \"off\"}, {\"attributes\": {\"Vera Device Id\": 6, \"friendly_name\": \"Couch Left Lamp\", \"supported_features\": 1}, \"entity_id\": \"light.couch_left_lamp\", \"last_changed\": \"2016-12-09T15:29:33.088762+00:00\", \"last_updated\": \"2016-12-09T15:29:33.088762+00:00\", \"state\": \"off\"}, {\"attributes\": {\"Vera Device Id\": 48, \"current_power_mwh\": 99000.0, \"friendly_name\": \"Kitchen\"}, \"entity_id\": \"switch.kitchen\", \"last_changed\": \"2016-12-09T15:38:34.682844+00:00\", \"last_updated\": \"2016-12-09T16:08:38.946423+00:00\", \"state\": \"on\"}, {\"attributes\": {\"Vera Device Id\": 35, \"friendly_name\": \"Living Room Accent\", \"supported_features\": 1}, \"entity_id\": \"light.living_room_accent\", \"last_changed\": \"2016-12-09T15:29:33.046514+00:00\", \"last_updated\": \"2016-12-09T15:29:33.046514+00:00\", \"state\": \"off\"}, {\"attributes\": {\"Vera Device Id\": 63, \"friendly_name\": \"HRM: TiVo DVR\"}, \"entity_id\": \"switch.hrm_tivo_dvr\", \"last_changed\": \"2016-12-09T15:29:33.195235+00:00\", \"last_updated\": \"2016-12-09T15:29:33.195235+00:00\", \"state\": \"off\"}, {\"attributes\": {\"Vera Device Id\": 47, \"friendly_name\": \"Harmony Control\"}, \"entity_id\": \"switch.harmony_control\", \"last_changed\": \"2016-12-09T15:29:33.200190+00:00\", \"last_updated\": \"2016-12-09T15:29:33.200190+00:00\", \"state\": \"off\"}, {\"attributes\": {\"Vera Device Id\": 44, \"friendly_name\": \"Fridge Light\", \"supported_features\": 1}, \"entity_id\": \"light.fridge_light\", \"last_changed\": \"2016-12-09T15:29:33.054270+00:00\", \"last_updated\": \"2016-12-09T15:29:33.054270+00:00\", \"state\": \"off\"}, {\"attributes\": {\"Vera Device Id\": 51, \"friendly_name\": \"Counter\"}, \"entity_id\": \"switch.counter\", \"last_changed\": \"2016-12-09T15:29:33.202557+00:00\", \"last_updated\": \"2016-12-09T15:29:33.202557+00:00\", \"state\": \"off\"}, {\"attributes\": {\"Vera Device Id\": 64, \"friendly_name\": \"X10 G2\"}, \"entity_id\": \"switch.x10_g2\", \"last_changed\": \"2016-12-09T15:29:33.190470+00:00\", \"last_updated\": \"2016-12-09T15:29:33.190470+00:00\", \"state\": \"off\"}, {\"attributes\": {\"Vera Device Id\": 28, \"friendly_name\": \"Desk Lamp\", \"supported_features\": 1}, \"entity_id\": \"light.desk_lamp\", \"last_changed\": \"2016-12-09T15:29:33.093874+00:00\", \"last_updated\": \"2016-12-09T15:29:33.093874+00:00\", \"state\": \"off\"}, {\"attributes\": {\"Vera Device Id\": 58, \"friendly_name\": \"Desk Outlet\"}, \"entity_id\": \"switch.desk_outlet\", \"last_changed\": \"2016-12-09T15:29:33.187971+00:00\", \"last_updated\": \"2016-12-09T15:29:33.187971+00:00\", \"state\": \"on\"}, {\"attributes\": {\"Vera Device Id\": 9, \"friendly_name\": \"Couch Right Lamp\", \"supported_features\": 1}, \"entity_id\": \"light.couch_right_lamp\", \"last_changed\": \"2016-12-09T15:29:33.077672+00:00\", \"last_updated\": \"2016-12-09T15:29:33.077672+00:00\", \"state\": \"off\"}, {\"attributes\": {\"Vera Device Id\": 61, \"friendly_name\": \"Test Light on CM15 (RF) M1\", \"supported_features\": 1}, \"entity_id\": \"light.test_light_on_cm15_rf_m1\", \"last_changed\": \"2016-12-09T15:29:33.091354+00:00\", \"last_updated\": \"2016-12-09T15:29:33.091354+00:00\", \"state\": \"off\"}, {\"attributes\": {\"auto\": true, \"entity_id\": [\"light.family_ceiling\", \"light.test_light_on_a_cm11\", \"light.living_room\", \"light.test_light_on_cm15_pl_n1\", \"light.fridge_light\", \"light.couch_left_lamp\", \"light.living_room_accent\", \"light.couch_right_lamp\", \"light.desk_lamp\", \"light.test_light_on_cm15_rf_m1\"], \"friendly_name\": \"all lights\", \"hidden\": true, \"order\": 0}, \"entity_id\": \"group.all_lights\", \"last_changed\": \"2016-12-09T15:29:33.100850+00:00\", \"last_updated\": \"2016-12-09T15:29:33.100850+00:00\", \"state\": \"off\"}, {\"attributes\": {\"auto\": true, \"entity_id\": [\"switch.x10_g2\", \"switch.kitchen\", \"switch.test_light_on_cm15_rf_p1\", \"switch.desk_outlet\", \"switch.counter\", \"switch.topiary_tree\", \"switch.house_b\", \"switch.hrm_tivo_dvr\", \"switch.harmony_control\"], \"friendly_name\": \"all switches\", \"hidden\": true, \"order\": 1}, \"entity_id\": \"group.all_switches\", \"last_changed\": \"2016-12-09T15:29:33.212637+00:00\", \"last_updated\": \"2016-12-09T15:29:33.212637+00:00\", \"state\": \"on\"}]"; + public static void main(String[] args){ + StateDataConstructor aTestReference = new StateDataConstructor(); + if(aTestReference.validateStructure()) + System.out.println("Test Successful"); + } + + public Boolean validateStructure() { + Gson aGson; + try { + aGson = new GsonBuilder().create(); + + State[] aTestObject = aGson.fromJson(TestData, State[].class); + for(int i = 0; i < aTestObject.length; i++) { + System.out.println( "<" + aTestObject[i].getEntityId() + ">,<" + aTestObject[i].getLastChanged() + ">,<" + aTestObject[i].getLastUpdated() + ">,<" + aTestObject[i].getState() + ">"); + if(aTestObject[i].getAttributes() != null) { + for(Entry theEntry:aTestObject[i].getAttributes().entrySet()) { + try { + System.out.println(" " + theEntry.getKey() + " <" + theEntry.getValue().getAsString() + ">"); + } catch(IllegalStateException e) { + System.out.println(" " + theEntry.getKey() + " "); + + } + } + } + } + } catch (Exception e) { + return false; + } + return true; + } +} diff --git a/src/test/java/com/bwssystems/hass/test/StateStructureTestCase.java b/src/test/java/com/bwssystems/hass/test/StateStructureTestCase.java new file mode 100644 index 0000000..8e98e62 --- /dev/null +++ b/src/test/java/com/bwssystems/hass/test/StateStructureTestCase.java @@ -0,0 +1,14 @@ +package com.bwssystems.hass.test; + +import org.junit.Assert; +import org.junit.Test; + +public class StateStructureTestCase { + + @Test + public void test() { + StateDataConstructor aTestTarget = new StateDataConstructor(); + Assert.assertEquals(aTestTarget.validateStructure(), true); + } + +}