Skip to content

Commit 08752f1

Browse files
cloudbr34k84claude
andcommitted
feat: Bronze quality scale — runtime_data, has_entity_name, data_description, removal docs, config flow tests
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9d68c92 commit 08752f1

File tree

13 files changed

+218
-13
lines changed

13 files changed

+218
-13
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ custom_components/
9999

100100
No changes to `configuration.yaml` are required.
101101

102+
## Removal
103+
104+
To remove the PocketSmith integration:
105+
106+
1. Go to **Settings → Integrations** in Home Assistant.
107+
2. Find **PocketSmith** and click on it.
108+
3. Click the three-dot menu (⋮) and select **Delete**.
109+
4. Confirm the removal.
110+
111+
All sensors and entities created by the integration will be removed automatically.
112+
102113
## Automation Examples
103114

104115
### Notify on Low Balance:

custom_components/ha_pocketsmith/__init__.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
1818

19+
type PocketSmithConfigEntry = ConfigEntry[PocketSmithCoordinator]
1920

20-
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
21+
22+
async def async_setup_entry(hass: HomeAssistant, entry: PocketSmithConfigEntry) -> bool:
2123
"""Set up PocketSmith from a config entry."""
2224
coordinator = PocketSmithCoordinator(
2325
hass,
@@ -26,17 +28,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
2628
entry=entry,
2729
)
2830
await coordinator.async_config_entry_first_refresh()
29-
hass.data.setdefault(DOMAIN, {})
30-
hass.data[DOMAIN][entry.entry_id] = coordinator
31+
entry.runtime_data = coordinator
3132

3233
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
3334

3435
return True
3536

3637

37-
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
38+
async def async_unload_entry(hass: HomeAssistant, entry: PocketSmithConfigEntry) -> bool:
3839
"""Handle unloading of an entry."""
39-
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
40-
if unload_ok:
41-
hass.data[DOMAIN].pop(entry.entry_id)
42-
return unload_ok
40+
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

custom_components/ha_pocketsmith/binary_sensor.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async def async_setup_entry(
2222
async_add_entities: AddEntitiesCallback,
2323
) -> None:
2424
"""Set up PocketSmith binary sensors from a config entry."""
25-
coordinator: PocketSmithCoordinator = hass.data[DOMAIN][entry.entry_id]
25+
coordinator: PocketSmithCoordinator = entry.runtime_data
2626

2727
async_add_entities([
2828
PocketSmithOverBudgetBinarySensor(coordinator),
@@ -34,6 +34,8 @@ async def async_setup_entry(
3434
class PocketSmithOverBudgetBinarySensor(CoordinatorEntity, BinarySensorEntity):
3535
"""Binary sensor that is on when any non-transfer category is over budget."""
3636

37+
_attr_has_entity_name = True
38+
3739
def __init__(self, coordinator: PocketSmithCoordinator) -> None:
3840
"""Initialise the sensor."""
3941
super().__init__(coordinator)
@@ -99,6 +101,8 @@ def extra_state_attributes(self) -> dict:
99101
class PocketSmithForecastNeedsRecalculateBinarySensor(CoordinatorEntity, BinarySensorEntity):
100102
"""Binary sensor that is on when the forecast is stale or missing."""
101103

104+
_attr_has_entity_name = True
105+
102106
def __init__(self, coordinator: PocketSmithCoordinator) -> None:
103107
"""Initialise the sensor."""
104108
super().__init__(coordinator)
@@ -155,6 +159,8 @@ def icon(self) -> str:
155159
class PocketSmithHasUncategorisedBinarySensor(CoordinatorEntity, BinarySensorEntity):
156160
"""Binary sensor that is on when there are uncategorised transactions."""
157161

162+
_attr_has_entity_name = True
163+
158164
def __init__(self, coordinator: PocketSmithCoordinator) -> None:
159165
"""Initialise the sensor."""
160166
super().__init__(coordinator)

custom_components/ha_pocketsmith/diagnostics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async def async_get_config_entry_diagnostics(
1515
hass: HomeAssistant, entry: ConfigEntry
1616
) -> dict[str, Any]:
1717
"""Return diagnostics for a PocketSmith config entry."""
18-
coordinator = hass.data[DOMAIN][entry.entry_id]
18+
coordinator = entry.runtime_data
1919
data = coordinator.data
2020

2121
return {

custom_components/ha_pocketsmith/sensor.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async def async_setup_entry(
5050
async_add_entities: AddEntitiesCallback,
5151
) -> None:
5252
"""Set up PocketSmith sensors from a config entry."""
53-
coordinator: PocketSmithCoordinator = hass.data[DOMAIN][entry.entry_id]
53+
coordinator: PocketSmithCoordinator = entry.runtime_data
5454

5555
sensors = [
5656
PocketSmithSensor(coordinator, account)
@@ -70,6 +70,8 @@ async def async_setup_entry(
7070
class PocketSmithSensor(CoordinatorEntity, SensorEntity):
7171
"""Representation of a PocketSmith account balance sensor."""
7272

73+
_attr_has_entity_name = True
74+
7375
def __init__(self, coordinator: PocketSmithCoordinator, account: dict) -> None:
7476
"""Initialise the sensor."""
7577
super().__init__(coordinator)
@@ -130,6 +132,8 @@ def extra_state_attributes(self) -> dict:
130132
class PocketSmithUncategorisedTransactions(CoordinatorEntity, SensorEntity):
131133
"""Sensor reporting the count of uncategorised transactions."""
132134

135+
_attr_has_entity_name = True
136+
133137
def __init__(self, coordinator: PocketSmithCoordinator) -> None:
134138
"""Initialise the sensor."""
135139
super().__init__(coordinator)
@@ -168,6 +172,8 @@ def icon(self) -> str:
168172
class PocketSmithCategoriesSensor(CoordinatorEntity, SensorEntity):
169173
"""Sensor reporting the total number of PocketSmith categories."""
170174

175+
_attr_has_entity_name = True
176+
171177
def __init__(self, coordinator: PocketSmithCoordinator) -> None:
172178
"""Initialise the sensor."""
173179
super().__init__(coordinator)
@@ -210,6 +216,8 @@ def extra_state_attributes(self) -> dict:
210216
class PocketSmithCategorySensor(CoordinatorEntity, SensorEntity):
211217
"""Sensor representing a single enriched PocketSmith category."""
212218

219+
_attr_has_entity_name = True
220+
213221
def __init__(self, coordinator: PocketSmithCoordinator, enriched_category: dict) -> None:
214222
"""Initialise the sensor."""
215223
super().__init__(coordinator)
@@ -280,6 +288,8 @@ def extra_state_attributes(self) -> dict:
280288
class PocketSmithNetWorthSensor(CoordinatorEntity, SensorEntity):
281289
"""Sensor reporting the total net worth across all accounts."""
282290

291+
_attr_has_entity_name = True
292+
283293
def __init__(self, coordinator: PocketSmithCoordinator) -> None:
284294
"""Initialise the sensor."""
285295
super().__init__(coordinator)
@@ -326,6 +336,8 @@ def icon(self) -> str:
326336
class PocketSmithUserSensor(CoordinatorEntity, SensorEntity):
327337
"""Sensor reporting PocketSmith user profile information."""
328338

339+
_attr_has_entity_name = True
340+
329341
def __init__(self, coordinator: PocketSmithCoordinator) -> None:
330342
"""Initialise the sensor."""
331343
super().__init__(coordinator)

custom_components/ha_pocketsmith/strings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"description": "Enter your PocketSmith developer key. You can find it under PocketSmith \u2192 Settings \u2192 API.",
77
"data": {
88
"developer_key": "Developer Key"
9+
},
10+
"data_description": {
11+
"developer_key": "Your PocketSmith developer API key. Find it in PocketSmith under Settings → API → Developer Keys."
912
}
1013
}
1114
},

custom_components/ha_pocketsmith/system_health.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ async def system_health_info(hass: HomeAssistant) -> dict[str, Any]:
2222

2323
entry = entries[0]
2424
try:
25-
coordinator = hass.data[DOMAIN][entry.entry_id]
26-
except KeyError:
25+
coordinator = entry.runtime_data
26+
except AttributeError:
2727
return {"api_reachable": False}
2828

2929
return {

custom_components/ha_pocketsmith/translations/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"description": "Enter your PocketSmith developer key. You can find it under PocketSmith \u2192 Settings \u2192 API.",
77
"data": {
88
"developer_key": "Developer Key"
9+
},
10+
"data_description": {
11+
"developer_key": "Your PocketSmith developer API key. Find it in PocketSmith under Settings → API → Developer Keys."
912
}
1013
}
1114
},

tests/__init__.py

Whitespace-only changes.

tests/components/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)