forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add diagnostics platform to Mastodon (home-assistant#123592)
Diagnostics
- Loading branch information
1 parent
e93d0df
commit be3e720
Showing
3 changed files
with
310 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Diagnostics support for the Mastodon integration.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
from homeassistant.core import HomeAssistant | ||
|
||
from . import MastodonConfigEntry | ||
|
||
|
||
async def async_get_config_entry_diagnostics( | ||
hass: HomeAssistant, config_entry: MastodonConfigEntry | ||
) -> dict[str, Any]: | ||
"""Return diagnostics for a config entry.""" | ||
|
||
instance, account = await hass.async_add_executor_job( | ||
get_diagnostics, | ||
config_entry, | ||
) | ||
|
||
return { | ||
"instance": instance, | ||
"account": account, | ||
} | ||
|
||
|
||
def get_diagnostics(config_entry: MastodonConfigEntry) -> tuple[dict, dict]: | ||
"""Get mastodon diagnostics.""" | ||
client = config_entry.runtime_data.client | ||
|
||
instance = client.instance() | ||
account = client.account_verify_credentials() | ||
|
||
return instance, account |
247 changes: 247 additions & 0 deletions
247
tests/components/mastodon/snapshots/test_diagnostics.ambr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
# serializer version: 1 | ||
# name: test_entry_diagnostics | ||
dict({ | ||
'account': dict({ | ||
'acct': 'trwnh', | ||
'avatar': 'https://files.mastodon.social/accounts/avatars/000/014/715/original/34aa222f4ae2e0a9.png', | ||
'avatar_static': 'https://files.mastodon.social/accounts/avatars/000/014/715/original/34aa222f4ae2e0a9.png', | ||
'bot': False, | ||
'created_at': '2016-11-24T10:02:12.085Z', | ||
'display_name': 'infinite love ⴳ', | ||
'emojis': list([ | ||
dict({ | ||
'shortcode': 'fatyoshi', | ||
'static_url': 'https://files.mastodon.social/custom_emojis/images/000/023/920/static/e57ecb623faa0dc9.png', | ||
'url': 'https://files.mastodon.social/custom_emojis/images/000/023/920/original/e57ecb623faa0dc9.png', | ||
'visible_in_picker': True, | ||
}), | ||
]), | ||
'fields': list([ | ||
dict({ | ||
'name': 'Website', | ||
'value': '<a href="https://trwnh.com" rel="me nofollow noopener noreferrer" target="_blank"><span class="invisible">https://</span><span class="">trwnh.com</span><span class="invisible"></span></a>', | ||
'verified_at': '2019-08-29T04:14:55.571+00:00', | ||
}), | ||
dict({ | ||
'name': 'Sponsor', | ||
'value': '<a href="https://liberapay.com/at" rel="me nofollow noopener noreferrer" target="_blank"><span class="invisible">https://</span><span class="">liberapay.com/at</span><span class="invisible"></span></a>', | ||
'verified_at': '2019-11-15T10:06:15.557+00:00', | ||
}), | ||
dict({ | ||
'name': 'Fan of:', | ||
'value': 'Punk-rock and post-hardcore (Circa Survive, letlive., La Dispute, THE FEVER 333)Manga (Yu-Gi-Oh!, One Piece, JoJo's Bizarre Adventure, Death Note, Shaman King)Platformers and RPGs (Banjo-Kazooie, Boktai, Final Fantasy Crystal Chronicles)', | ||
'verified_at': None, | ||
}), | ||
dict({ | ||
'name': 'Main topics:', | ||
'value': 'systemic analysis, design patterns, anticapitalism, info/tech freedom, theory and philosophy, and otherwise being a genuine and decent wholesome poster. i'm just here to hang out and talk to cool people!', | ||
'verified_at': None, | ||
}), | ||
]), | ||
'followers_count': 821, | ||
'following_count': 178, | ||
'header': 'https://files.mastodon.social/accounts/headers/000/014/715/original/5c6fc24edb3bb873.jpg', | ||
'header_static': 'https://files.mastodon.social/accounts/headers/000/014/715/original/5c6fc24edb3bb873.jpg', | ||
'id': '14715', | ||
'last_status_at': '2019-11-24T15:49:42.251Z', | ||
'locked': False, | ||
'note': '<p>i have approximate knowledge of many things. perpetual student. (nb/ace/they)</p><p>xmpp/email: [email protected]<br /><a href="https://trwnh.com" rel="nofollow noopener noreferrer" target="_blank"><span class="invisible">https://</span><span class="">trwnh.com</span><span class="invisible"></span></a><br />help me live: <a href="https://liberapay.com/at" rel="nofollow noopener noreferrer" target="_blank"><span class="invisible">https://</span><span class="">liberapay.com/at</span><span class="invisible"></span></a> or <a href="https://paypal.me/trwnh" rel="nofollow noopener noreferrer" target="_blank"><span class="invisible">https://</span><span class="">paypal.me/trwnh</span><span class="invisible"></span></a></p><p>- my triggers are moths and glitter<br />- i have all notifs except mentions turned off, so please interact if you wanna be friends! i literally will not notice otherwise<br />- dm me if i did something wrong, so i can improve<br />- purest person on fedi, do not lewd in my presence<br />- #1 ami cole fan account</p><p>:fatyoshi:</p>', | ||
'source': dict({ | ||
'fields': list([ | ||
dict({ | ||
'name': 'Website', | ||
'value': 'https://trwnh.com', | ||
'verified_at': '2019-08-29T04:14:55.571+00:00', | ||
}), | ||
dict({ | ||
'name': 'Sponsor', | ||
'value': 'https://liberapay.com/at', | ||
'verified_at': '2019-11-15T10:06:15.557+00:00', | ||
}), | ||
dict({ | ||
'name': 'Fan of:', | ||
'value': "Punk-rock and post-hardcore (Circa Survive, letlive., La Dispute, THE FEVER 333)Manga (Yu-Gi-Oh!, One Piece, JoJo's Bizarre Adventure, Death Note, Shaman King)Platformers and RPGs (Banjo-Kazooie, Boktai, Final Fantasy Crystal Chronicles)", | ||
'verified_at': None, | ||
}), | ||
dict({ | ||
'name': 'Main topics:', | ||
'value': "systemic analysis, design patterns, anticapitalism, info/tech freedom, theory and philosophy, and otherwise being a genuine and decent wholesome poster. i'm just here to hang out and talk to cool people!", | ||
'verified_at': None, | ||
}), | ||
]), | ||
'follow_requests_count': 0, | ||
'language': '', | ||
'note': ''' | ||
i have approximate knowledge of many things. perpetual student. (nb/ace/they) | ||
|
||
xmpp/email: [email protected] | ||
https://trwnh.com | ||
help me live: https://liberapay.com/at or https://paypal.me/trwnh | ||
|
||
- my triggers are moths and glitter | ||
- i have all notifs except mentions turned off, so please interact if you wanna be friends! i literally will not notice otherwise | ||
- dm me if i did something wrong, so i can improve | ||
- purest person on fedi, do not lewd in my presence | ||
- #1 ami cole fan account | ||
|
||
:fatyoshi: | ||
''', | ||
'privacy': 'public', | ||
'sensitive': False, | ||
}), | ||
'statuses_count': 33120, | ||
'url': 'https://mastodon.social/@trwnh', | ||
'username': 'trwnh', | ||
}), | ||
'instance': dict({ | ||
'configuration': dict({ | ||
'accounts': dict({ | ||
'max_featured_tags': 10, | ||
'max_pinned_statuses': 4, | ||
}), | ||
'media_attachments': dict({ | ||
'image_matrix_limit': 16777216, | ||
'image_size_limit': 10485760, | ||
'supported_mime_types': list([ | ||
'image/jpeg', | ||
'image/png', | ||
'image/gif', | ||
'image/heic', | ||
'image/heif', | ||
'image/webp', | ||
'video/webm', | ||
'video/mp4', | ||
'video/quicktime', | ||
'video/ogg', | ||
'audio/wave', | ||
'audio/wav', | ||
'audio/x-wav', | ||
'audio/x-pn-wave', | ||
'audio/vnd.wave', | ||
'audio/ogg', | ||
'audio/vorbis', | ||
'audio/mpeg', | ||
'audio/mp3', | ||
'audio/webm', | ||
'audio/flac', | ||
'audio/aac', | ||
'audio/m4a', | ||
'audio/x-m4a', | ||
'audio/mp4', | ||
'audio/3gpp', | ||
'video/x-ms-asf', | ||
]), | ||
'video_frame_rate_limit': 60, | ||
'video_matrix_limit': 2304000, | ||
'video_size_limit': 41943040, | ||
}), | ||
'polls': dict({ | ||
'max_characters_per_option': 50, | ||
'max_expiration': 2629746, | ||
'max_options': 4, | ||
'min_expiration': 300, | ||
}), | ||
'statuses': dict({ | ||
'characters_reserved_per_url': 23, | ||
'max_characters': 500, | ||
'max_media_attachments': 4, | ||
}), | ||
'translation': dict({ | ||
'enabled': True, | ||
}), | ||
'urls': dict({ | ||
'streaming': 'wss://mastodon.social', | ||
}), | ||
'vapid': dict({ | ||
'public_key': 'BCkMmVdKDnKYwzVCDC99Iuc9GvId-x7-kKtuHnLgfF98ENiZp_aj-UNthbCdI70DqN1zUVis-x0Wrot2sBagkMc=', | ||
}), | ||
}), | ||
'contact': dict({ | ||
'account': dict({ | ||
'acct': 'Gargron', | ||
'avatar': 'https://files.mastodon.social/accounts/avatars/000/000/001/original/dc4286ceb8fab734.jpg', | ||
'avatar_static': 'https://files.mastodon.social/accounts/avatars/000/000/001/original/dc4286ceb8fab734.jpg', | ||
'bot': False, | ||
'created_at': '2016-03-16T00:00:00.000Z', | ||
'discoverable': True, | ||
'display_name': 'Eugen 💀', | ||
'emojis': list([ | ||
]), | ||
'fields': list([ | ||
dict({ | ||
'name': 'Patreon', | ||
'value': '<a href="https://www.patreon.com/mastodon" target="_blank" rel="nofollow noopener noreferrer me"><span class="invisible">https://www.</span><span class="">patreon.com/mastodon</span><span class="invisible"></span></a>', | ||
'verified_at': None, | ||
}), | ||
]), | ||
'followers_count': 133026, | ||
'following_count': 311, | ||
'group': False, | ||
'header': 'https://files.mastodon.social/accounts/headers/000/000/001/original/3b91c9965d00888b.jpeg', | ||
'header_static': 'https://files.mastodon.social/accounts/headers/000/000/001/original/3b91c9965d00888b.jpeg', | ||
'id': '1', | ||
'last_status_at': '2022-10-31', | ||
'locked': False, | ||
'noindex': False, | ||
'note': '<p>Founder, CEO and lead developer <span class="h-card"><a href="https://mastodon.social/@Mastodon" class="u-url mention">@<span>Mastodon</span></a></span>, Germany.</p>', | ||
'statuses_count': 72605, | ||
'url': 'https://mastodon.social/@Gargron', | ||
'username': 'Gargron', | ||
}), | ||
'email': '[email protected]', | ||
}), | ||
'description': 'The original server operated by the Mastodon gGmbH non-profit', | ||
'domain': 'mastodon.social', | ||
'languages': list([ | ||
'en', | ||
]), | ||
'registrations': dict({ | ||
'approval_required': False, | ||
'enabled': False, | ||
'message': None, | ||
}), | ||
'rules': list([ | ||
dict({ | ||
'id': '1', | ||
'text': 'Sexually explicit or violent media must be marked as sensitive when posting', | ||
}), | ||
dict({ | ||
'id': '2', | ||
'text': 'No racism, sexism, homophobia, transphobia, xenophobia, or casteism', | ||
}), | ||
dict({ | ||
'id': '3', | ||
'text': 'No incitement of violence or promotion of violent ideologies', | ||
}), | ||
dict({ | ||
'id': '4', | ||
'text': 'No harassment, dogpiling or doxxing of other users', | ||
}), | ||
dict({ | ||
'id': '5', | ||
'text': 'No content illegal in Germany', | ||
}), | ||
dict({ | ||
'id': '7', | ||
'text': 'Do not share intentionally false or misleading information', | ||
}), | ||
]), | ||
'source_url': 'https://github.com/mastodon/mastodon', | ||
'thumbnail': dict({ | ||
'blurhash': 'UeKUpFxuo~R%0nW;WCnhF6RjaJt757oJodS$', | ||
'url': 'https://files.mastodon.social/site_uploads/files/000/000/001/@1x/57c12f441d083cde.png', | ||
'versions': dict({ | ||
'@1x': 'https://files.mastodon.social/site_uploads/files/000/000/001/@1x/57c12f441d083cde.png', | ||
'@2x': 'https://files.mastodon.social/site_uploads/files/000/000/001/@2x/57c12f441d083cde.png', | ||
}), | ||
}), | ||
'title': 'Mastodon', | ||
'usage': dict({ | ||
'users': dict({ | ||
'active_month': 123122, | ||
}), | ||
}), | ||
'version': '4.0.0rc1', | ||
}), | ||
}) | ||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Test Mastodon diagnostics.""" | ||
|
||
from unittest.mock import AsyncMock | ||
|
||
from syrupy import SnapshotAssertion | ||
|
||
from homeassistant.core import HomeAssistant | ||
|
||
from . import setup_integration | ||
|
||
from tests.common import MockConfigEntry | ||
from tests.components.diagnostics import get_diagnostics_for_config_entry | ||
from tests.typing import ClientSessionGenerator | ||
|
||
|
||
async def test_entry_diagnostics( | ||
hass: HomeAssistant, | ||
hass_client: ClientSessionGenerator, | ||
mock_mastodon_client: AsyncMock, | ||
mock_config_entry: MockConfigEntry, | ||
snapshot: SnapshotAssertion, | ||
) -> None: | ||
"""Test config entry diagnostics.""" | ||
await setup_integration(hass, mock_config_entry) | ||
assert ( | ||
await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry) | ||
== snapshot | ||
) |