diff --git a/custom_components/nea_sg_weather/const.py b/custom_components/nea_sg_weather/const.py index bae2201897..6d9771d8eb 100644 --- a/custom_components/nea_sg_weather/const.py +++ b/custom_components/nea_sg_weather/const.py @@ -176,6 +176,417 @@ "Yishun", ] +RAIN_SENSOR_LIST = [ + { + "id": "S77", + "device_id": "S77", + "name": "Alexandra Road", + "location": {"latitude": 1.2937, "longitude": 103.8125}, + }, + { + "id": "S109", + "device_id": "S109", + "name": "Ang Mo Kio Avenue 5", + "location": {"latitude": 1.3764, "longitude": 103.8492}, + }, + { + "id": "S90", + "device_id": "S90", + "name": "Bukit Timah Road", + "location": {"latitude": 1.3191, "longitude": 103.8191}, + }, + { + "id": "S114", + "device_id": "S114", + "name": "Choa Chu Kang Avenue 4", + "location": {"latitude": 1.38, "longitude": 103.73}, + }, + { + "id": "S50", + "device_id": "S50", + "name": "Clementi Road", + "location": {"latitude": 1.3337, "longitude": 103.7768}, + }, + { + "id": "S107", + "device_id": "S107", + "name": "East Coast Parkway", + "location": {"latitude": 1.3135, "longitude": 103.9625}, + }, + { + "id": "S215", + "device_id": "S215", + "name": "GEYLANG EAST CENTRAL", + "location": {"latitude": 1.32785, "longitude": 103.88899}, + }, + { + "id": "S118", + "device_id": "S118", + "name": "Handy Road", + "location": {"latitude": 1.2994, "longitude": 103.8461}, + }, + { + "id": "S120", + "device_id": "S120", + "name": "Holland Road", + "location": {"latitude": 1.30874, "longitude": 103.818}, + }, + { + "id": "S33", + "device_id": "S33", + "name": "Jurong Pier Road", + "location": {"latitude": 1.3081, "longitude": 103.71}, + }, + { + "id": "S71", + "device_id": "S71", + "name": "Kent Ridge Road", + "location": {"latitude": 1.2923, "longitude": 103.7815}, + }, + { + "id": "S43", + "device_id": "S43", + "name": "Kim Chuan Road", + "location": {"latitude": 1.3399, "longitude": 103.8878}, + }, + { + "id": "S66", + "device_id": "S66", + "name": "Kranji Way", + "location": {"latitude": 1.4387, "longitude": 103.7363}, + }, + { + "id": "S112", + "device_id": "S112", + "name": "Lim Chu Kang Road", + "location": {"latitude": 1.43854, "longitude": 103.70131}, + }, + { + "id": "S40", + "device_id": "S40", + "name": "Mandai Lake Road", + "location": {"latitude": 1.4044, "longitude": 103.78962}, + }, + { + "id": "S108", + "device_id": "S108", + "name": "Marina Gardens Drive", + "location": {"latitude": 1.2799, "longitude": 103.8703}, + }, + { + "id": "S113", + "device_id": "S113", + "name": "Marine Parade Road", + "location": {"latitude": 1.30648, "longitude": 103.9104}, + }, + { + "id": "S44", + "device_id": "S44", + "name": "Nanyang Avenue", + "location": {"latitude": 1.34583, "longitude": 103.68166}, + }, + { + "id": "S119", + "device_id": "S119", + "name": "Nicoll Highway", + "location": {"latitude": 1.30105, "longitude": 103.8666}, + }, + { + "id": "S121", + "device_id": "S121", + "name": "Old Choa Chu Kang Road", + "location": {"latitude": 1.37288, "longitude": 103.72244}, + }, + { + "id": "S35", + "device_id": "S35", + "name": "Old Toh Tuck Road", + "location": {"latitude": 1.3329, "longitude": 103.7556}, + }, + { + "id": "S94", + "device_id": "S94", + "name": "Pasir Ris Street 51", + "location": {"latitude": 1.3662, "longitude": 103.9528}, + }, + { + "id": "S78", + "device_id": "S78", + "name": "Poole Road", + "location": {"latitude": 1.30703, "longitude": 103.89067}, + }, + { + "id": "S106", + "device_id": "S106", + "name": "Pulau Ubin", + "location": {"latitude": 1.4168, "longitude": 103.9673}, + }, + { + "id": "S81", + "device_id": "S81", + "name": "Punggol Central", + "location": {"latitude": 1.4029, "longitude": 103.9092}, + }, + { + "id": "S201", + "device_id": "S201", + "name": "S201", + "location": {"latitude": 1.32311, "longitude": 103.76714}, + }, + { + "id": "S202", + "device_id": "S202", + "name": "S202", + "location": {"latitude": 1.30968, "longitude": 103.7578}, + }, + { + "id": "S203", + "device_id": "S203", + "name": "S203", + "location": {"latitude": 1.29164, "longitude": 103.7702}, + }, + { + "id": "S204", + "device_id": "S204", + "name": "S204", + "location": {"latitude": 1.40081, "longitude": 103.88217}, + }, + { + "id": "S205", + "device_id": "S205", + "name": "S205", + "location": {"latitude": 1.38829, "longitude": 103.9116}, + }, + { + "id": "S207", + "device_id": "S207", + "name": "S207", + "location": {"latitude": 1.32485, "longitude": 103.95836}, + }, + { + "id": "S208", + "device_id": "S208", + "name": "S208", + "location": {"latitude": 1.3136, "longitude": 104.00317}, + }, + { + "id": "S209", + "device_id": "S209", + "name": "S209", + "location": {"latitude": 1.42111, "longitude": 103.84472}, + }, + { + "id": "S210", + "device_id": "S210", + "name": "S210", + "location": {"latitude": 1.44003, "longitude": 103.76904}, + }, + { + "id": "S211", + "device_id": "S211", + "name": "S211", + "location": {"latitude": 1.42918, "longitude": 103.75711}, + }, + { + "id": "S212", + "device_id": "S212", + "name": "S212", + "location": {"latitude": 1.31835, "longitude": 103.93574}, + }, + { + "id": "S213", + "device_id": "S213", + "name": "S213", + "location": {"latitude": 1.32427, "longitude": 103.8097}, + }, + { + "id": "S214", + "device_id": "S214", + "name": "S214", + "location": {"latitude": 1.29911, "longitude": 103.88289}, + }, + { + "id": "S216", + "device_id": "S216", + "name": "S216", + "location": {"latitude": 1.36019, "longitude": 103.85335}, + }, + { + "id": "S217", + "device_id": "S217", + "name": "S217", + "location": {"latitude": 1.35041, "longitude": 103.85526}, + }, + { + "id": "S218", + "device_id": "S218", + "name": "S218", + "location": {"latitude": 1.36491, "longitude": 103.75065}, + }, + { + "id": "S219", + "device_id": "S219", + "name": "S219", + "location": {"latitude": 1.37999, "longitude": 103.87643}, + }, + { + "id": "S220", + "device_id": "S220", + "name": "S220", + "location": {"latitude": 1.38666, "longitude": 103.89797}, + }, + { + "id": "S221", + "device_id": "S221", + "name": "S221", + "location": {"latitude": 1.35691, "longitude": 103.89088}, + }, + { + "id": "S222", + "device_id": "S222", + "name": "S222", + "location": {"latitude": 1.28987, "longitude": 103.82364}, + }, + { + "id": "S223", + "device_id": "S223", + "name": "S223", + "location": {"latitude": 1.29984, "longitude": 103.80264}, + }, + { + "id": "S224", + "device_id": "S224", + "name": "S224", + "location": {"latitude": 1.34392, "longitude": 103.98409}, + }, + { + "id": "S226", + "device_id": "S226", + "name": "S226", + "location": {"latitude": 1.27472, "longitude": 103.80389}, + }, + { + "id": "S227", + "device_id": "S227", + "name": "S227", + "location": {"latitude": 1.43944, "longitude": 103.80389}, + }, + { + "id": "S228", + "device_id": "S228", + "name": "S228", + "location": {"latitude": 1.34703, "longitude": 103.70073}, + }, + { + "id": "S229", + "device_id": "S229", + "name": "S229", + "location": {"latitude": 1.35167, "longitude": 103.72195}, + }, + { + "id": "S230", + "device_id": "S230", + "name": "S230", + "location": {"latitude": 1.30167, "longitude": 103.76444}, + }, + { + "id": "S111", + "device_id": "S111", + "name": "Scotts Road", + "location": {"latitude": 1.31055, "longitude": 103.8365}, + }, + { + "id": "S900", + "device_id": "S900", + "name": "Seletar Aerospace View", + "location": {"latitude": 1.41284, "longitude": 103.86922}, + }, + { + "id": "S84", + "device_id": "S84", + "name": "Simei Avenue", + "location": {"latitude": 1.3437, "longitude": 103.9444}, + }, + { + "id": "S79", + "device_id": "S79", + "name": "Somerset Road", + "location": {"latitude": 1.3004, "longitude": 103.8372}, + }, + { + "id": "S88", + "device_id": "S88", + "name": "Toa Payoh North", + "location": {"latitude": 1.3427, "longitude": 103.8482}, + }, + { + "id": "S123", + "device_id": "S123", + "name": "Towner Road", + "location": {"latitude": 1.3214, "longitude": 103.8577}, + }, + { + "id": "S89", + "device_id": "S89", + "name": "Tuas Road", + "location": {"latitude": 1.31985, "longitude": 103.66162}, + }, + { + "id": "S115", + "device_id": "S115", + "name": "Tuas South Avenue 3", + "location": {"latitude": 1.29377, "longitude": 103.61843}, + }, + { + "id": "S82", + "device_id": "S82", + "name": "Tuas West Road", + "location": {"latitude": 1.3247, "longitude": 103.6351}, + }, + { + "id": "S24", + "device_id": "S24", + "name": "Upper Changi Road North", + "location": {"latitude": 1.3678, "longitude": 103.9826}, + }, + { + "id": "S69", + "device_id": "S69", + "name": "Upper Peirce Reservoir Park", + "location": {"latitude": 1.37, "longitude": 103.805}, + }, + { + "id": "S36", + "device_id": "S36", + "name": "Upper Serangoon Road", + "location": {"latitude": 1.3382, "longitude": 103.8657}, + }, + { + "id": "S08", + "device_id": "S08", + "name": "Upper Thomson Road", + "location": {"latitude": 1.3701, "longitude": 103.8271}, + }, + { + "id": "S116", + "device_id": "S116", + "name": "West Coast Highway", + "location": {"latitude": 1.281, "longitude": 103.754}, + }, + { + "id": "S104", + "device_id": "S104", + "name": "Woodlands Avenue 9", + "location": {"latitude": 1.44387, "longitude": 103.78538}, + }, + { + "id": "S100", + "device_id": "S100", + "name": "Woodlands Road", + "location": {"latitude": 1.4172, "longitude": 103.74855}, + }, +] + REGIONS = ["West", "East", "Central", "South", "North"] PRIMARY_ENDPOINTS = { diff --git a/custom_components/nea_sg_weather/nea.py b/custom_components/nea_sg_weather/nea.py index c1b9ccf6df..d4728194eb 100644 --- a/custom_components/nea_sg_weather/nea.py +++ b/custom_components/nea_sg_weather/nea.py @@ -22,6 +22,7 @@ FORECAST_MAP_CONDITION, FORECAST_ICON_MAP_CONDITION, HEADERS, + RAIN_SENSOR_LIST, ) INV_FORECAST_ICON_MAP_CONDITION = dict() @@ -488,18 +489,29 @@ def process_data(self): resp_data = self._resp["items"][0]["readings"] self.metadata = self._resp["metadata"]["stations"] - self.station_list = [station["id"] for station in self.metadata] + self.station_list = RAIN_SENSOR_LIST + _current_station_list = [ + reading["station_id"] for reading in resp_data["items"][0]["readings"] + ] self.data = dict() - for i, reading in enumerate(resp_data): - self.data[reading["station_id"]] = { - "value": reading["value"], - "name": self.metadata[i]["name"], - "location": { - "latitude": self.metadata[i]["location"]["latitude"], - "longitude": self.metadata[i]["location"]["longitude"], - }, - } + + for station, i in enumerate(self.station_list): + station_id = station["id"] + try: + j = _current_station_list.index(station_id) + self.data[station_id] = { + "value": resp_data["items"][0]["readings"][j]["value"], + "name": self.station_list[i]["name"], + "location": self.station_list[i]["location"], + } + except (KeyError, ValueError): + _LOGGER.debug("%s is missing, setting values as 0", station_id) + self.data[station_id] = { + "value": 0, + "name": self.station_list[i]["name"], + "location": self.station_list[i]["location"], + } _LOGGER.debug("%s: Data processed", self.__class__.__name__) return