async def main(): """Sample code to retrieve the data from an OpenSenseMap station.""" async with aiohttp.ClientSession() as session: station = OpenSenseMap(SENSOR_ID, session) # Print details about the given station await station.get_data() print("Name:", station.name) print("Description:", station.description) print("Coordinates:", station.coordinates) print("PM 2.5:", station.pm2_5) print("PM 10:", station.pm10) print("Temperature:", station.temperature)
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the openSenseMap air quality platform.""" name = config.get(CONF_NAME) station_id = config[CONF_STATION_ID] session = async_get_clientsession(hass) osm_api = OpenSenseMapData(OpenSenseMap(station_id, hass.loop, session)) await osm_api.async_update() if "name" not in osm_api.api.data: _LOGGER.error("Station %s is not available", station_id) raise PlatformNotReady station_name = osm_api.api.data["name"] if name is None else name async_add_entities([OpenSenseMapQuality(station_name, osm_api)], True)
async def async_setup_platform( hass: HomeAssistant, config: ConfigType, async_add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the openSenseMap air quality platform.""" name = config.get(CONF_NAME) station_id = config[CONF_STATION_ID] session = async_get_clientsession(hass) osm_api = OpenSenseMapData(OpenSenseMap(station_id, session)) await osm_api.async_update() if "name" not in osm_api.api.data: _LOGGER.error("Station %s is not available", station_id) raise PlatformNotReady station_name = osm_api.api.data["name"] if name is None else name async_add_entities([OpenSenseMapQuality(station_name, osm_api)], True)