-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Songpal code and test improvement #35318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1185164
Use tests.async_mock instead of asynctest
shenxn 5874722
Remove unnecessary existence check
shenxn 0551e09
Improve songpal service registering
shenxn d8556f9
Add tests
shenxn f7cae88
Seperate device api from entity api
shenxn 5ab7256
Improve disconnect log messages
shenxn 5a06853
Improve tests
shenxn 1a34a5f
Rename SongpalDevice to SongpalEntity
shenxn 84165b3
Improve reconnecting
shenxn b53964e
Remove logging and sleep patch from tests
shenxn f0482d4
Test unavailable state when disconnected
shenxn 2a5ea02
Rename SongpalEntity.dev to _dev
shenxn b4eac99
Add quality scale to manifest
shenxn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1,104 @@ | ||
| """Test the songpal integration.""" | ||
| from songpal import SongpalException | ||
|
|
||
| from homeassistant.components.songpal.const import CONF_ENDPOINT | ||
| from homeassistant.const import CONF_NAME | ||
|
|
||
| from tests.async_mock import AsyncMock, MagicMock, patch | ||
|
|
||
| FRIENDLY_NAME = "name" | ||
| ENTITY_ID = f"media_player.{FRIENDLY_NAME}" | ||
| HOST = "0.0.0.0" | ||
| ENDPOINT = f"http://{HOST}:10000/sony" | ||
| MODEL = "model" | ||
| MAC = "mac" | ||
| SW_VERSION = "sw_ver" | ||
|
|
||
| CONF_DATA = { | ||
| CONF_NAME: FRIENDLY_NAME, | ||
| CONF_ENDPOINT: ENDPOINT, | ||
| } | ||
|
|
||
|
|
||
| def _create_mocked_device(throw_exception=False): | ||
| mocked_device = MagicMock() | ||
|
|
||
| type(mocked_device).get_supported_methods = AsyncMock( | ||
| side_effect=SongpalException("Unable to do POST request: ") | ||
| if throw_exception | ||
| else None | ||
| ) | ||
|
|
||
| interface_info = MagicMock() | ||
| interface_info.modelName = MODEL | ||
| type(mocked_device).get_interface_information = AsyncMock( | ||
| return_value=interface_info | ||
| ) | ||
|
|
||
| sys_info = MagicMock() | ||
| sys_info.macAddr = MAC | ||
| sys_info.version = SW_VERSION | ||
| type(mocked_device).get_system_info = AsyncMock(return_value=sys_info) | ||
|
|
||
| volume1 = MagicMock() | ||
| volume1.maxVolume = 100 | ||
| volume1.minVolume = 0 | ||
| volume1.volume = 50 | ||
| volume1.is_muted = False | ||
| volume1.set_volume = AsyncMock() | ||
| volume1.set_mute = AsyncMock() | ||
| volume2 = MagicMock() | ||
| volume2.maxVolume = 100 | ||
| volume2.minVolume = 0 | ||
| volume2.volume = 20 | ||
| volume2.is_muted = True | ||
| mocked_device.volume1 = volume1 | ||
| type(mocked_device).get_volume_information = AsyncMock( | ||
| return_value=[volume1, volume2] | ||
| ) | ||
|
|
||
| power = MagicMock() | ||
| power.status = True | ||
| type(mocked_device).get_power = AsyncMock(return_value=power) | ||
|
|
||
| input1 = MagicMock() | ||
| input1.title = "title1" | ||
| input1.uri = "uri1" | ||
| input1.active = False | ||
| input1.activate = AsyncMock() | ||
| mocked_device.input1 = input1 | ||
| input2 = MagicMock() | ||
| input2.title = "title2" | ||
| input2.uri = "uri2" | ||
| input2.active = True | ||
| type(mocked_device).get_inputs = AsyncMock(return_value=[input1, input2]) | ||
|
|
||
| type(mocked_device).set_power = AsyncMock() | ||
| type(mocked_device).set_sound_settings = AsyncMock() | ||
| type(mocked_device).listen_notifications = AsyncMock() | ||
| type(mocked_device).stop_listen_notifications = AsyncMock() | ||
|
|
||
| notification_callbacks = {} | ||
| mocked_device.notification_callbacks = notification_callbacks | ||
|
|
||
| def _on_notification(name, callback): | ||
| notification_callbacks[name] = callback | ||
|
|
||
| type(mocked_device).on_notification = MagicMock(side_effect=_on_notification) | ||
| type(mocked_device).clear_notification_callbacks = MagicMock() | ||
|
|
||
| return mocked_device | ||
|
|
||
|
|
||
| def _patch_config_flow_device(mocked_device): | ||
| return patch( | ||
| "homeassistant.components.songpal.config_flow.Device", | ||
| return_value=mocked_device, | ||
| ) | ||
|
|
||
|
|
||
| def _patch_media_player_device(mocked_device): | ||
| return patch( | ||
| "homeassistant.components.songpal.media_player.Device", | ||
| return_value=mocked_device, | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.