SuSu DaDDy

[SmartThings] 인증을 잃어버린 SmartApp 삭제

by SuSu Daddy
반응형

[참조]

- HA SmartThings 연동

 

[HA] SmartThings 연동

2019년 02월 릴리즈된 HomeAssistant V0.87에서 제공된 SmartThings 공식 연동방법에 대한 포스팅입니다. Integrations List of the built-in integrations of Home Assistant. www.home-assistant.io [사전 준비]..

inganyoyo.tistory.com

HomeAssistant와 SmartThings 연동 후 HomeAssistant의 SmartThings 인증관련 정보가 삭제되었을때 SmartThings App에서 HomeAssistant를 삭제할 수 없는 문제를 해결하는 방법에 대한 포스팅입니다.

 

[문제점 발견]

- 여러가지 작업(뻘짓)을 하던 중 ST Classic App에서 Home Assistant 앱이 여러개가 설치된 것을 발견 후 삭제하려 클릭 하였으나 오류가 발생하며 삭제가 되지 않는다. 원하지 않는 SmartApps이 삭제도 되지 않아 스트레스를 받기 시작하여 원인을 찾기 시작.

[원인 찾기]

- 원인을 찾기 위해 HomeAssistant log파일을 확인한 결과 오류가 발생할 때 아래와 같이 등록되지 않은 webhook메세지가 들어오는 것을 확인

2019-06-23 13:16:38 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/webhook/a568c9117a2dcfb96a32a0444f01b59a4af6d61e2ae5b2e8fc51c01aebc3ea8d to 127.0.0.1 (auth: False)
2019-06-23 13:16:38 WARNING (MainThread) [homeassistant.components.webhook] Received message for unregistered webhook a568c9117a2dcfb96a32a0444f01b59a4af6d61e2ae5b2e8fc51c01aebc3ea8d

- Google 검색을 통해 나와 같은 문제점을 겪는 사람이 있다는 것을 발견하게 되고 HomeAssistant에서 SmartThings 연동을 개발한 사람이 원인에 대해 게시한 댓글을 보게되었다. 

 

Unregistered Webhook Warnings caused by Orphaned Smartthings SmartApp · Issue #21462 · home-assistant/home-assistant

Home Assistant release with the issue: 0.88.1 Last working Home Assistant release (if known): 0.87.1 Operating environment (Hass.io/Docker/Windows/etc.): Docker Client: Version: 18.09.0 API version...

github.com

 

간략하게 원인을 보면 HomeAssistant의 .stoage\smartthings 파일에는 SmartThings와 연동을 위한 식별 정보가 저장되는데 개인의 실수 또는 HomeAssistant 업데이트 작업을 하다 파일이 삭제될 경우 SmartThings App의 정보가 분실되어 일명 "고아 스마트앱"이 된다.

Ah, so the integration supports any number of HASS instances controlling the same SmartThings account and it knows which one is which because of an identifier in .storage\smartthings. If you removed that file (inadvertently while reverting) and setup the integration again, it doesn't know about the previous install and we loose the ability to validate the webhooks that come in when you go to remove it in the SmartThings App.
All is not lost though, it can still be deleted through the API directly. I'll write a utility this evening which you can run to delete those orphaned instance(s).
Thanks for your patience!

 

[해결하기]

1. 개발자가 문제를 해결하기 위한 스크립트를 작성 후 공개하였다. (1차 실패)

pip install hass_smartthings_remove
hass_smartthings_remove PERSONAL_ACCESS_TOKEN
 

hass-smartthings-remove

Utility that removes SmartApps created by the Home Assistant SmartThings integration.

pypi.org

hass_smartthings_remove를 설치 후 삭제를 하였으나 SSL인증 관련 오류가 발생하였다. 당황은 하였으나 어차피 SmartThings에서 제공하는 API를 통해 진행되는 것이기에 SmartThings API 문서를 찾았다.

 

2. SmartThings API를 통한 문제 해결(완료)

- SmartThings API를 확인한 결과 OAuth 2.0 Bearer Tokens 을 통해 통신하는 것을 확인.

 

SmartThings API

 

smartthings.developer.samsung.com

- Rest API 통신을 위해 별도로 프로그램밍 언어를 통해 진행하여도 되지만 크롬 확장프로그램에 간편하게 사용하기 좋은 POSTMAN이 등록되어 그냥 사용하기로 결정하였습니다.(크롬 확장 프로그램에 POSTMAN 검색 후 설치하시면 됩니다)

   

- 설치된 app 조회하기

 url: https://api.smartthings.com/v1/installedapps

 HEADER: Authorization // Bearer XXXX.  (XXXX: SmartTings TOKEN: HA SmartThings 연동 과정에서 발급 받은 TOKEN)

 

정보를 입력 후 Send 버튼을 클릭하게 되면 아래와 같이 결과값이 나타나게 된다.

{
  "items": [
    {
      "installedAppId": "8885b9c3-a50d-427e-ad07-d7a2f94421af",
      "installedAppType": "WEBHOOK_SMART_APP",
      "installedAppStatus": "PENDING",
      "displayName": "Color App",
      "appId": "fdd21b3e-5880-44c8-9f61-ce474814f587",
      "referenceId": "c71b0a5b-7dab-41fe-b75f-7cf30246468e",
      "locationId": "4ae86cfc-63be-4bcc-8514-836c873b4d7a",
      "owner": {
        "ownerType": "USER",
        "ownerId": "3f178632-79ed-4358-94de-280dbd7c206c"
      },
      "createdDate": "2019-06-22T10:30:00.164Z",
      "lastUpdatedDate": "2019-06-22T10:30:00.164Z"
    }
  ],
  "_links": {
    "next": {
      "href": "https://..."
    },
    "previous": {
      "href": "https://..."
    }
  }
}

- 고아가 된 App 삭제

 API 문서를 참조하면 삭제를 위해서는 "installedAppId"가 필요하여 우리는 위에서 설치된 App을 조회하며 installedAppId 값을 찾아 필요한 모든 정보가 있습니다.

 

 url: https://api.smartthings.com/v1/installedapps/{installedAppId}

 HEADER: Authorization // Bearer XXXX.  (XXXX: SmartTings TOKEN: HA SmartThings 연동 과정에서 발급 받은 TOKEN)

 REST API METHOD: DELETE

 

모든 정보를 입력후 Send 버튼 클릭시 response count: 1로 삭제된 App의 건수가 표시되며 정상적으로 삭제됨을 확인 할 수 있습니다.

 

[완료]

- 위의 과정을 모두 완료하였다면 갈길잃은 SmartApps이 모두 삭제된 것을 확인 가능 합니다.

 

[추가]

- 위의 내용은 installedapp을 삭제하는 방법입니다.

- 추가적으로 스마트앱 추가화면에 등록된 App은 apps API (https://smartthings.developer.samsung.com/docs/api-ref/st-api.html#tag/apps)를 통해 삭제 가능합니다.

반응형

블로그의 정보

SuSu Daddy

SuSu Daddy

활동하기