From fab64c9cd8ba591114fac66e7eb47240e1cf7b60 Mon Sep 17 00:00:00 2001 From: Zhaoyang Date: Sun, 19 Apr 2026 15:55:33 +0800 Subject: [PATCH 1/2] Add indexes_short attribute --- custom_components/tianqi/weather.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/custom_components/tianqi/weather.py b/custom_components/tianqi/weather.py index f6a83b4..965ebd5 100644 --- a/custom_components/tianqi/weather.py +++ b/custom_components/tianqi/weather.py @@ -132,6 +132,7 @@ async def update_from_client(self): ]} indexes = {} + indexes_short = {} for k, v in dataZS.items(): if '_name' not in k: continue @@ -139,8 +140,12 @@ async def update_from_client(self): if not (des := dataZS.get(f'{key}_des_s')): continue indexes[v] = des + if hint := dataZS.get(f'{key}_hint'): + indexes_short[v.removesuffix('指数')] = hint if indexes: self._attr_extra_state_attributes['indexes'] = indexes + if indexes_short: + self._attr_extra_state_attributes['indexes_short'] = indexes_short forecasts = await self.async_forecast_daily() if hasattr(self, '_attr_forecast'): From f58eadc8d9e174fcca0f9249df17214aa0f77ccb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 16 Jun 2026 13:23:29 +0000 Subject: [PATCH 2/2] Sort alarms by severity desc, fix entity_picture and title ordering --- custom_components/tianqi/converters/base.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/custom_components/tianqi/converters/base.py b/custom_components/tianqi/converters/base.py index 56274a2..22aeac6 100644 --- a/custom_components/tianqi/converters/base.py +++ b/custom_components/tianqi/converters/base.py @@ -119,8 +119,15 @@ def decode(self, client: "Client", payload: dict, value: Any): code = None titles = [] alarms = [] - for v in client.data.get(self.prop) or []: - code = f'{v.get("w4")}{v.get("w6")}' + raw_alarms = sorted( + client.data.get(self.prop) or [], + key=lambda v: v.get('w6', ''), + reverse=True, + ) + for v in raw_alarms: + alarm_code = f'{v.get("w4")}{v.get("w6")}' + if code is None: + code = alarm_code title = v.get('w13', '') titles.append(re.sub(r'.+发布的?(.+预警)', r'\1', title)) alarms.append({ @@ -128,12 +135,12 @@ def decode(self, client: "Client", payload: dict, value: Any): 'description': v.get('w9', ''), 'province': v.get('w1'), 'city': v.get('w2'), - 'code': code, + 'code': alarm_code, 'alertld': v.get('w16'), 'link': client.web_url('warning/publish_area.shtml?code=%s' % client.area_id), }) payload['warning'] = len(alarms) > 0 - payload['title'] = ', '.join(set(titles)) + payload['title'] = ', '.join(dict.fromkeys(titles)) payload['alarms'] = alarms src = client.web_url('m2/i/about/alarmpic/%s.gif' % code, 'www') if code else None self.option['entity_picture'] = f'https://cfrp.hacs.vip/{src}' if src else None