Skip to content

Add Camera platform to Prosegur#76428

Merged
balloob merged 10 commits into
home-assistant:devfrom
dgomes:prosegur_camera
Feb 27, 2023
Merged

Add Camera platform to Prosegur#76428
balloob merged 10 commits into
home-assistant:devfrom
dgomes:prosegur_camera

Conversation

@dgomes
Copy link
Copy Markdown
Contributor

@dgomes dgomes commented Aug 7, 2022

Proposed change

Adds the camera platform to the integration

Changelog of pyprosegur: dgomes/pyprosegur@0.0.5...0.0.8

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

Comment thread homeassistant/components/prosegur/alarm_control_panel.py Outdated
Comment thread homeassistant/components/prosegur/camera.py Outdated
Comment thread homeassistant/components/prosegur/diagnostics.py Outdated
@epenet
Copy link
Copy Markdown
Contributor

epenet commented Aug 8, 2022

Also, please remember to add a link to changelog

@dgomes
Copy link
Copy Markdown
Contributor Author

dgomes commented Aug 25, 2022

Example diagnostic dump:

{
  "home_assistant": {
    "installation_type": "Home Assistant Core",
    "version": "2022.9.0.dev0",
    "dev": true,
    "hassio": false,
    "virtualenv": true,
    "python_version": "3.10.6",
    "docker": false,
    "arch": "x86_64",
    "timezone": "Europe/Lisbon",
    "os_name": "Darwin",
    "os_version": "12.5.1",
    "run_as_root": false
  },
  "custom_components": {
    "openhasp": {
      "version": "0.6.5",
      "requirements": [
        "jsonschema>=3.2.0"
      ]
    },
    "generic_water_heater": {
      "version": "0.0.3",
      "requirements": []
    },
    "hacs": {
      "version": "1.26.2",
      "requirements": [
        "aiogithubapi>=22.2.4"
      ]
    },
    "erse": {
      "version": "2.1.5",
      "requirements": [
        "pyerse==0.0.4"
      ]
    }
  },
  "integration_manifest": {
    "domain": "prosegur",
    "name": "Prosegur Alarm",
    "config_flow": true,
    "documentation": "https://www.home-assistant.io/integrations/prosegur",
    "requirements": [
      "pyprosegur==0.0.8"
    ],
    "codeowners": [
      "@dgomes"
    ],
    "iot_class": "cloud_polling",
    "loggers": [
      "pyprosegur"
    ],
    "is_built_in": true
  },
  "data": {
    "installation": {
      "installationId": "1102262",
      "description": "**REDACTED**",
      "image": 1,
      "installationType": "RSI",
      "pinControl": false,
      "status": "DA",
      "preboarding": false,
      "hasDomotic": false,
      "detectors": [
        {
          "id": "884540",
          "description": "**REDACTED**",
          "type": "Camera",
          "streaming": false
        },
        {
          "id": "884541",
          "description": "**REDACTED**",
          "type": "Camera",
          "streaming": false
        },
        {
          "id": "884542",
          "description": "**REDACTED**",
          "type": "Camera",
          "streaming": false
        }
      ],
      "videoDetectors": [],
      "services": [
        {
          "type": "A",
          "statusCode": 200
        },
        {
          "type": "V",
          "statusCode": 200
        },
        {
          "type": "PB",
          "statusCode": 200
        }
      ],
      "partitions": [],
      "domoticDevices": [],
      "accessLevels": [],
      "latitude": "**REDACTED**",
      "longitude": "**REDACTED**",
      "contractId": "**REDACTED**",
      "address": "**REDACTED**"
    },
    "activity": {
      "result": {
        "code": 200,
        "message": "User events list found successfully",
        "description": "OK"
      },
      "data": [
        {
          "id": "4606293595",
          "installationId": "1102262",
          "connectionId": "B20029219",
          "logId": "-1",
          "description": "Disarming by DGOMES",
          "operation": "DA",
          "creationDate": 1661412894000
        },
        {
          "id": "4605999545",
          "installationId": "1102262",
          "connectionId": "B20029219",
          "logId": "-1",
          "description": "Full arming by DGOMES",
          "operation": "AT",
          "creationDate": 1661388353000
        }
      ]
    }
  }
}

@github-actions
Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

platform.async_register_entity_service(
SERVICE_REQUEST_IMAGE,
{},
"async_request_image",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this? We have an update entity service

Copy link
Copy Markdown
Contributor Author

@dgomes dgomes Dec 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The camera sends a still picture through an MMS service, so it's not advisable to update periodically and only use it seldomly (Prosegur will throttle your request heavily).

Prosegur Mobile App also requires this explicit request.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more explanation:

  • The alarm camera will trigger on it's self based on motion sensing and send image to Prosegur server
  • User might request an out of order camera capture (that's the service I'm proposing)

This service is therefore independent from update entity service which will periodically get the last camera capture available on Prosegur server.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This service is therefore independent from update entity service which will periodically get the last camera capture available on Prosegur server.

The update entity service allows to request a single update (yes, it could be used periodically in an automation, but by itself it isn't periodically).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update_service -> request image from Prosegur server
request_image -> request Prosegur to refresh it's server stored image

Comment thread homeassistant/components/prosegur/services.yaml
Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. 1 tiny change.

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
@balloob balloob merged commit c8fc2dc into home-assistant:dev Feb 27, 2023
@dgomes
Copy link
Copy Markdown
Contributor Author

dgomes commented Feb 27, 2023

Thanks! 🎉

@dgomes dgomes deleted the prosegur_camera branch February 27, 2023 08:44
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the comments in a new PR. Thanks!

Comment thread homeassistant/components/prosegur/camera.py
Comment thread tests/components/prosegur/conftest.py
@pytest.fixture
def mock_install() -> AsyncMock:
"""Return the mocked alarm install."""
install = AsyncMock()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The installation doesn't need to be an AsyncMock. It can be a MagicMock or Mock.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually does:

    async def async_alarm_arm_home(self, code: str | None = None) -> None:
        """Send arm away command."""
>       await self._installation.arm_partially(self._auth)
E       TypeError: object MagicMock can't be used in 'await' expression

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either mock the attributes of the installation explicitly or spec the installation according to the original target.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread tests/components/prosegur/test_camera.py
@dgomes dgomes restored the prosegur_camera branch February 27, 2023 20:22
dgomes added a commit to dgomes/home-assistant that referenced this pull request Feb 27, 2023
dgomes added a commit to dgomes/home-assistant that referenced this pull request Feb 27, 2023
@dgomes dgomes mentioned this pull request Feb 27, 2023
19 tasks
MartinHjelmare pushed a commit that referenced this pull request Feb 28, 2023
* address late comments on #76428

* adress review

* extra tweaks
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants