<commit_before>"""Entity tests for mobile_app."""
# pylint: disable=redefined-outer-name,unused-import
import logging

from . import (authed_api_client, create_registrations,  # noqa: F401
               webhook_client)  # noqa: F401

_LOGGER = logging.getLogger(__name__)


async def test_sensor(hass, create_registrations, webhook_client):  # noqa: F401, F811, E501
    """Test that sensors can be registered and updated."""
    webhook_id = create_registrations[1]['webhook_id']
    webhook_url = '/api/webhook/{}'.format(webhook_id)

    reg_resp = await webhook_client.post(
        webhook_url,
        json={
            'type': 'register_sensor',
            'data': {
                'attributes': {
                    'foo': 'bar'
                },
                'device_class': 'battery',
                'icon': 'mdi:battery',
                'name': 'Battery State',
                'state': 100,
                'type': 'sensor',
                'unique_id': 'battery_state',
                'unit_of_measurement': '%'
            }
        }
    )

    assert reg_resp.status == 201

    json = await reg_resp.json()
    assert json == {'status': 'registered'}

    # 3 because we require device_tracker which adds zone.home and
    # group.all_devices
    assert len(hass.states.async_all()) == 3

    entity = hass.states.async_all()[2]

    assert entity.attributes['device_class'] == 'battery'
    assert entity.attributes['icon'] == 'mdi:battery'
    assert entity.attributes['unit_of_measurement'] == '%'
    assert entity.attributes['foo'] == 'bar'
    assert entity.domain == 'sensor'<commit_msg>Fix test<commit_after>"""Entity tests for mobile_app."""
# pylint: disable=redefined-outer-name,unused-import
import logging

from . import (authed_api_client, create_registrations,  # noqa: F401
               webhook_client)  # noqa: F401

_LOGGER = logging.getLogger(__name__)


async def test_sensor(hass, create_registrations, webhook_client):  # noqa: F401, F811, E501
    """Test that sensors can be registered and updated."""
    webhook_id = create_registrations[1]['webhook_id']
    webhook_url = '/api/webhook/{}'.format(webhook_id)

    reg_resp = await webhook_client.post(
        webhook_url,
        json={
            'type': 'register_sensor',
            'data': {
                'attributes': {
                    'foo': 'bar'
                },
                'device_class': 'battery',
                'icon': 'mdi:battery',
                'name': 'Battery State',
                'state': 100,
                'type': 'sensor',
                'unique_id': 'battery_state',
                'unit_of_measurement': '%'
            }
        }
    )

    assert reg_resp.status == 201

    json = await reg_resp.json()
    assert json == {'status': 'registered'}

    entity = hass.states.get('sensor.battery_state')
    assert entity is not None

    assert entity.attributes['device_class'] == 'battery'
    assert entity.attributes['icon'] == 'mdi:battery'
    assert entity.attributes['unit_of_measurement'] == '%'
    assert entity.attributes['foo'] == 'bar'
    assert entity.domain == 'sensor'
{'fraction_non_alphanumeric': 0.13187162376866857, 'fraction_numerical': 0.014934858595487766, 'mean_word_length': 2.3740621650589495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1777629', 'n_tokens_mistral': 998, 'n_tokens_neox': 936, 'n_words': 200}