Skip to content

Commit

Permalink
Support for 1.0 endpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Iván Sánchez Ortega <ivan@sanchezortega.es>
  • Loading branch information
IvanSanchez committed Apr 26, 2023
1 parent a961433 commit e06b6b6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- Enable the [HACS](https://hacs.xyz/) integration in your Home Assistant instance.
- Use the side menu to browse HACS.
- Navigate to "Integrations", then use the overflow menu (three dots at the top-right) to add a Custom Repository.
- Enter the URL `https://github.com/IvanSanchez/homeassistant-sensorthingss`, of type "Integration"
- Enter the URL `https://github.com/IvanSanchez/homeassistant-sensorthings`, of type "Integration"
- You should see a new box labelled "OGC Sensorthings". Click on it and follow HACS' instructions to download and enable the integration.
- Restart Home Assistant when HACS tells you to.

Expand All @@ -32,6 +32,7 @@ Configuration only requires the base URL of the OGC SensorThings endpoint (inclu

Even though this integration implements a OGC SensorThings client, and has been tested with several SensorThings endpoints, it has **not** undergone any OGC compliance tests.

This integration implements only part 1 of the standard (Sensing), and not part 2 (Tasking). It works for endpoints implementing either [1.0 part 1](http://www.opengis.net/doc/is/sensorthings/1.0) or [1.1 part 1]((http://www.opengis.net/doc/is/sensorthings/1.1).

## License

Expand Down
7 changes: 3 additions & 4 deletions custom_components/sensorthings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# This is called when an entry/configured device is to be removed. The class
# needs to unload itself, and remove callbacks. See the classes for further
# details
# print ("freeds unload entry", entry.data)

unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
# unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
# if unload_ok:
# hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok
21 changes: 15 additions & 6 deletions custom_components/sensorthings/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async def async_step_user(

return self.async_create_entry(title=url, data={
"url": url,
"version": info['version']
})

except Exception: # pylint: disable=broad-except
Expand Down Expand Up @@ -73,20 +74,28 @@ async def _async_get_info(self, url):

values = json['value']

conformances = json['serverSettings']['conformance']
if 'serverSettings' in json:
conformances = json['serverSettings']['conformance']

if not 'http://www.opengis.net/spec/iot_sensing/1.1/req/datamodel' in conformances:
return {'error': 'not_conforming'}
if not 'http://www.opengis.net/spec/iot_sensing/1.1/req/request-data' in conformances:
return {'error': 'not_conforming'}
if not 'http://www.opengis.net/spec/iot_sensing/1.1/req/datamodel' in conformances:
return {'error': 'not_conforming'}
if not 'http://www.opengis.net/spec/iot_sensing/1.1/req/request-data' in conformances:
return {'error': 'not_conforming'}
version = "1.1"
else:
version = "1.0"

# This integration depends on OGC-ST Datastreams, Things and Observations,
# so they must exist in the endpoint
if not any(x['name'] == 'Datastreams' for x in values):
return {'error': 'not_conforming'}
if not any(x['name'] == 'Things' for x in values):
return {'error': 'not_conforming'}
if not any(x['name'] == 'Observations' for x in values):
return {'error': 'not_conforming'}


# TODO: Return conformance classes (and save them in the config entry)
# In particular, store whether the endpoint sends updates via MQTT.
return {'url': url}
return {'url': url, 'version': version}

2 changes: 1 addition & 1 deletion custom_components/sensorthings/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "cloud_poll",
"issue_tracker": "https://gitlab.com/IvanSanchez/homeassistant-sensorthings/-/issues",
"requirements": [],
"version": "0.1.0"
"version": "0.2.0"
}

0 comments on commit e06b6b6

Please sign in to comment.