diff --git a/example.py b/example.py index 4b3148a..01400d6 100644 --- a/example.py +++ b/example.py @@ -5,7 +5,7 @@ from opensensemap_api import OpenSenseMap -SENSOR_ID = "5a528c40fa02ec000fe9058a" +SENSOR_ID = "63b83dcc6795ba0007794c93" async def main(): @@ -19,11 +19,21 @@ async def main(): print("Name:", station.name) print("Description:", station.description) print("Coordinates:", station.coordinates) + print("Model:", station.model) + print("Exposure:", station.exposure) + print("PM 1.0:", station.pm1_0) print("PM 2.5:", station.pm2_5) print("PM 10:", station.pm10) print("Temperature:", station.temperature) + print("Humidity:", station.humidity) + print("Pressure:", station.air_pressure) + print("Wind Speed:", station.wind_speed) + print("Wind Direction:", station.wind_direction) + print("Precipitation:", station.precipitation) + print("Illuminance:", station.illuminance) + print("UV Index:", station.uv) if __name__ == "__main__": diff --git a/opensensemap_api/__init__.py b/opensensemap_api/__init__.py index bdd5ccb..d1e06d7 100644 --- a/opensensemap_api/__init__.py +++ b/opensensemap_api/__init__.py @@ -12,28 +12,39 @@ _INSTANCE = "https://api.opensensemap.org/boxes/{id}" _TITLES = { - "Air pressure": ( + "Air Pressure": ( + "Pressure", "Luftdruck", "Ilmanpaine", - ), # fi + ), "Humidity": ( "rel. Luftfeuchte", + "rel. Humidity", "Ilmankosteus", "Kosteus", - ), # fi + ), "Illuminance": ( "Beleuchtungsstärke", "Valoisuus", - "Valaistuksen voimakkuus", # fi + "Valaistuksen voimakkuus", + "Ambient Light", ), "Temperature": ( "Temperatur", "Lämpötila", - ), # fi + ), "UV": ( + "UV Index", "UV-Intensität", "UV-säteily", - ), # fi + ), + "Precipitation": ( + "Rain", + "Regen", + "Niederschlag", + ), + "Wind Speed": ("Windgeschwindigkeit",), + "Wind Direction": ("Windrichtung",), } @@ -78,6 +89,22 @@ def coordinates(self): """Return the coordinates of the station.""" return self.data["currentLocation"]["coordinates"] + @property + def exposure(self): + """Return the exposure of the station.""" + try: + return self.data["exposure"] + except KeyError: + return None + + @property + def model(self): + """Return the model of the station.""" + try: + return self.data["model"] + except KeyError: + return None + @property def pm10(self): """Return the particulate matter 10 value.""" @@ -88,6 +115,11 @@ def pm2_5(self): """Return the particulate matter 2.5 value.""" return self.get_value("PM2.5") + @property + def pm1_0(self): + """Return the particulate matter 1.0 value.""" + return self.get_value("PM1.0") + @property def temperature(self): """Return the temperature of a station.""" @@ -106,7 +138,7 @@ def vcc(self): @property def air_pressure(self): """Return the current air pressure of a station.""" - return self.get_value("Air pressure") + return self.get_value("Air Pressure") @property def illuminance(self): @@ -123,6 +155,21 @@ def radioactivity(self): """Return the current radioactivity value of a station.""" return self.get_value("Radioactivity") + @property + def wind_speed(self): + """Return the current wind speed value of a station.""" + return self.get_value("Wind Speed") + + @property + def wind_direction(self): + """Return the current wind direction value of a station.""" + return self.get_value("Wind Direction") + + @property + def precipitation(self): + """Return the current precipitation value of a station.""" + return self.get_value("Precipitation") + def get_value(self, key): """Extract a value for a given key.""" for title in _TITLES.get(key, ()) + (key,): @@ -130,7 +177,9 @@ def get_value(self, key): value = [ entry["lastMeasurement"]["value"] for entry in self.data["sensors"] - if entry["title"] == title + if entry["title"].casefold() == title.casefold() + and "lastMeasurement" in entry + and "value" in entry["lastMeasurement"] ][0] return value except (IndexError, TypeError): diff --git a/setup.py b/setup.py index e42a959..8a212ca 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name="opensensemap-api", - version="0.3.1", + version="0.3.2", description="Python client for interacting with the openSenseMap API.", long_description=long_description, url="https://github.com/home-assistant-ecosystem/python-opensensemap-api",